faysal faysal - 1 year ago 114
SQL Question

django complex datamodel

I am creating a small Django project which show stats collected from twitter data
for example my tables are

id hashname tweetPosted trendDate userid
1 #abc 44 2-2-2016 @xyz
2 #abc 55 2-2-2016 @qwer
3 #xcs 55 3-2-2016 @qwer
4 #xcs 55 4-2-2016 @qwer

id userid profileImage profileImage
1 @xyz image2.jpg www.abc.com
2 @qwer image3.jpg www.xadf.com

for this if i create models.py

class userDetails(models.Model):
userid= models.CharField(max_length=30)
profileImage= models.CharField(max_length=30)
profileImage= models.CharField(max_length=30)

class hashDetails(models.Model):
hashname= models.CharField(max_length=30)
tweetPosted= models.IntegerField()
trendDate= models.DateTimeField()
userid = models.ForeignKey(userDetails, to_field ='userid')

but i don't wanna make userid unique cause

i want something like i can enter data in both table manually
and when i query in my view it will search result from both table
if i want all trends by @xyz
or if i want list of all users who did #abc trend
or if i want result of all trends in specific date

in short i want both table to behave like one
I can't use userid as unique my daily data will be about 20MB so you can assume its difficult to find ids

Answer Source

I found one solution of my problem and its working for me i just create normal 2 model without foreignkey or any relation and define my function in views.py and got my result what i want

def teamdetail(request,test_id):
    hashd = hashDetails.objects.get(hashname=test_id)
    userd=  userDetails.objects.all()
    context = {'hashinfo': hashd, 'username':userd}
    return render(request,'test/hashDetails.html',context)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download