Edit instance for ModelChoiceField not getting selected selected

2011-06-05 Thread sushanth Reddy

Hi,

When i edit a records  none of the modelchoicefields are getting selected 
using form edit form instance.

I have gone though below blog, but confusing

http://blog.brendel.com/2009/07/setting-initial-value-for-djangos.html


*view.py* :

def EditTable(request, get_id):
  detail_data = shortcuts.get_object_or_404(models.TestTable, id=get_id)
  if request.method == 'POST':
form = forms.EditForm(
request, data=request.POST, instance=detail_data)
if form_is_valid():
form.save()
  else:
form  =  forms.EditForm(instance=detail_data)
 return form

*form.py*

class EditForm(forms.ModelForm):
  activity = forms.TypedChoiceField(choices=choice.Activity_CHOICES)
  def __init__(self,  *args, **kwargs):
super(EditForm, self).__init__(*args, **kwargs)
self.fields['b_name'] = forms.ModelChoiceField(
queryset=models.CreateDb.objects.filter( list_p='English', 
status='A'),
self.fields['type'] = forms.ModelChoiceField(
queryset=models.CreateType.objects.filter( list_T='Grammer', 
status='A'),

I any help really appreciate. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/eGVYTVF2bU04YmNK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ORM Doubts

2011-06-03 Thread sushanth Reddy
 

Hi,

below is model

class Employee(models.Model):
  name = models.CharField(max_length=50, primary_key=True)
  dep = models.CharField(max_length=10)
  class Meta(object):
db_table = u'employee'

class EmpSal(models.Model):
  emp_name = models.ForeignKey(Employee, db_column='emp_name')
  emp_sal = models.FloatField()
  class Meta(object):
db_table = u'empsal'

class EmpWork(models.Model):
  emp_wrk = models.ForeignKey(Employee, db_column='emp_wrk')
  emp_doj = models.DateField()
  class Meta(object):
db_table = u'empwork'

here i can make join from EMployee and EmpWork

 EmpWork.object.filter(emp_wrk__dep)

here i can make join from EMployee and EmpSal

   EmpSal.object.filter(emp_name__dep)

My Questions:

   - 
   
   how to make a relation between EmpWork and EMPSal 
   - 
   
   how to join all three once Employee,EMPWork,EMPSal
   - if i want to make a relation 

Employee.objects.filter(empsal__emp_sal=1).values('name') ?

this return empty list ?

   - how to get all the employee sal who's doj is example '2010-10-15' ? 

If possible can you please give example with making relation with ORM

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/R0xscklQV0NOUXdK.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Model filter on date ranges

2011-05-24 Thread sushanth Reddy
Thank you for the response,Let me give a try and let you know.


Thanks & Regards
sushanth reddy


On Tue, May 24, 2011 at 12:30 PM, Ori Livneh  wrote:

> Check out the python-dateutil <http://labix.org/python-dateutil> module
> (not in the standard lib, but available via pip and easy_install). It makes
> calculating time deltas easy.
>
> Anyways, try something like this:
>
> #!/usr/bin/env python
> from datetime import datetime
> from dateutil.relativedelta import relativedelta
>
> employees = {}
> now = datetime.now()
> ranges = [(0, 3), (3, 6), (6, 12), (12, 24)]
>
> for (a, b) in ranges:
> start_date = now - relativedelta(months=b)
> end_date = now - relativedelta(months=a)
> employees[(a, b)] = Employees.objects.filter(
> doj_date__range=(start_date, end_date))
>
> On Mon, May 23, 2011 at 3:45 PM, sushanth Reddy wrote:
>
>> Hi,
>>
>> How to get model filter on date ranges. In my project using employee doj,
>> i need to deign a table. like employee who have joined less than three
>> months , 3-6month, 6-12 months, 12-24 months.
>>
>> Depart  < 3month  3-6months   6-12months  12-24months
>>
>>
>> -  -
>>
>>
>>
>>   A dep   46 6   8
>>
>>
>>
>> --
>>
>>
>>  How to do this filter in django.
>>
>> I have gone through this link ,but its confusing .
>>
>> http://www.nerdydork.com/django-filter-model-on-date-range.html
>>
>> Thanks in Advance
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Model filter on date ranges

2011-05-23 Thread sushanth Reddy


Hi,

How to get model filter on date ranges. In my project using employee doj, i 
need to deign a table. like employee who have joined less than three months 
, 3-6month, 6-12 months, 12-24 months.

Depart  < 3month  3-6months   6-12months  12-24months
-  -
  A dep   46 6   8

--

How to do this filter in django.

I have gone through this link ,but its confusing .

http://www.nerdydork.com/django-filter-model-on-date-range.html

Thanks in Advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: My tool to generate django code

2011-05-21 Thread sushanth Reddy
This is awesome Brice,

Nice Work

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Google motion chart problem in django template

2011-05-17 Thread sushanth Reddy
Hi Tarkeshwar,

Thank you for the response,But here i am directly passing list to the 
template, 
Can you please help me how to extract that list into that date format.

Thanks in advance

sushanth

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to aggreate in html django

2011-03-12 Thread sushanth Reddy
Hi Tom,

I given try but not printing any values in html.
can you please add some more code

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Sum in html template using template tag

2011-03-12 Thread sushanth Reddy
it worked,thanks aaa ton

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django remove unicode from query result ?

2011-03-11 Thread sushanth Reddy
Hi JAson,

Thanks a ton,it worked

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Sum in html template using template tag

2011-03-11 Thread sushanth Reddy
Hi ,

I am trying to sum in HTML,but template tag return 0 ,


View.py

def gen_Report(request):

### query returns below output 
list=[{'total': 1744, 'user': u'x'}, {'total': 13, 'user': u'y'}, 
{'total': 126, 'user': u'z'}, {'total': 46, 'user': u'm'}, {'total': 4, 
'user': u'n'}, {'total': 8, 'user': u'o'},  {'total': 3, 'user': u'p'}]

return render_to_response('user.html', locals(),
context_instance = RequestContext(request))

Template :

user.html

  {% load temptags %}

 



S.No
role
Count
  


{% for fetch in list %}


{{forloop.counter}}
{{fetch.user}}
{{fetch.total}}



{% endfor %}
{{ list.total|running_total}}




Template tag:


from django.template import Library
register = Library()
@register.filter
def running_total(role_total):
  return sum(d.get('list_sum') for d in list_total)



output :

S.Nouser  Count
1  x  1744
2  y13
3  z126
4  m46
5  n  4
6  o 8
Sum-->   0  (it returns zero)

I am doing anything wrong here ?

can you please help me,how to return sum total using template tag here ?




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django remove unicode from query result ?

2011-03-10 Thread sushanth Reddy
I using jplot in my app .if list is in unicode(u) ,it not displaying the 
charts,thats the reason i want to remove it ...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django remove unicode from query result ?

2011-03-10 Thread sushanth Reddy
Hi,

Django query gives me below output  format,but i want below format

date=`[{'total': 1744, 'name: u'x'}, {'total': 13, 'name': u'm'}, 
{'total': 126, 'role': name'n'}]`
m=[]
for i in m:
   m.append(i.values())

   
print m
it give me output

[[1744,u'x'], [13,u'm'], [126,u'n']]

but i need output in
how to remove unicode symbol from output 

[['x',1744], ['m',13], ['n',126]]

how to do this ?

Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to log model inserts,updates and deletes

2011-03-10 Thread sushanth Reddy
hi,

how to log model inserts,updates and deletes?
I am not using django admin,in my app there are multiple tables
i just want to records only which  model or table name, field name,previous 
value,who edited,and what time
to one log table?

Who edited (my app uses SSO,it should pick up remote user automatically) 

can you please suggest any built in function or module in django to records 
this kind of logs ,if possible can you plz add few lines of django code or 
any ref links?

Thanks in advance

Thanks 
Sushanth

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to write data to csv using DictWriter

2011-03-09 Thread sushanth Reddy
thanks you for the link ,KG

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to write data to csv using DictWriter

2011-03-09 Thread sushanth Reddy
I have gone through to that documentation,but output in wired format ,plz 
add few lines of codes to undersstand better


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to write data to csv using DictWriter

2011-03-09 Thread sushanth Reddy
Hi,


How to write  below data to csv in below output format ?


list of dict


data=[{'date': datetime.date(2011, 2, 8), 'user': u'xxx', 'status': 
u'P'}, {'date': datetime.date(2011, 2, 8), 'user': u'yyy', 'status': u'P'}, 
{'date': datetime.date(2011, 2, 8), 'user': u'zzz', 'status': u'P'}, 
{'date': datetime.date(2011, 2, 9), 'user': u'xxx, 'status': u'P'}, {'date': 
datetime.date(2011, 2, 9), 'user': u'yyy', 'status': u'E'}, {'date': 
datetime.date(2011, 2, 9), 'user': u'zzz', 'status': u'E'}, {'date': 
datetime.date(2011, 2, 10), 'user': u'xxx', 'status': u'P'}, {'date': 
datetime.date(2011, 2, 10), 'user': u'yyy', 'status': u'P'}, {'date': 
datetime.date(2011, 2, 10), 'user': u'zzz', 'status': u'P'}]


Output format should be :

S.no  user  2011-02-08 2011-02-09 2011-02-10  p-total E-total total 
 1xxx  p  p p   3   0   3
 2yyy  p  E p   2   1   3
 3zzz  p  E E   1   2   3




 code :

 import csv
 from datetime import datetime,date
 
  d=28
  for i in xrange(1,d):
   date_format = now.replace( year = 2011 , month = 02 , day = i )
   writer = csv.DictWriter(f, ['S.no', 'user', 
'date_format','p-total','E-total','Total'])
   how to write to items to csv  ?

Please need help 
   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to aggreate in html django

2011-03-07 Thread sushanth Reddy
Hi Tom,

Can you please  add few lines of code example,
to make code more efficient?sorry for troubling.  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to aggreate in html django

2011-03-07 Thread sushanth Reddy
Hi ,

I want to make total at the end of the each row,i have explained the details 
in below
link.

http://stackoverflow.com/questions/5223093/how-to-aggreate-in-html-django

Can you please help me 

Thanks in advance

sushanth

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django csv header and row format problem

2011-03-07 Thread sushanth Reddy
Hi,

I am trying to create csv download ,but results download gives me in 
different format

below is the link which gives the details of the problem 
http://stackoverflow.com/questions/5222841/django-csv-header-and-row-format-problem

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



error while submitting data in the form django

2011-02-08 Thread sushanth Reddy
I am trying to insert data into db it throws below error,can any please fix 
this.


model.py

from django.db import models

# Create your models here.

class Profile(models.Model):
 name = models.CharField(max_length=50, primary_key=True)
 assign = models.CharField(max_length=50)
 doj = models.DateField()

 class Meta:
db_table= 'profile'


 def __unicode__(self):

   return  u'%s' % (self.name)



class working(models.Model):
   w_name =models.ForeignKey(Profile, db_column='w_name')
   monday =  models.IntegerField(null=True, db_column='monday', blank=True)
   tuesday =  models.IntegerField(null=True, db_column='tuesday', blank=True)
   wednesday =  models.IntegerField(null=True, db_column='wednesday', 
blank=True)

   class Meta:
db_table = 'working'



   def __unicode__(self):
  return  u'%s ' % ( self.w_name)

forms.py

from models import *
from django import forms

class WorkingForm(forms.ModelForm):

  def __init__(self,  *args, **kwargs):
super(WorkingForm, self).__init__(*args, **kwargs)
self.fields['w_name'] 
=forms.CharField(initial='x',widget=forms.HiddenInput())

  class Meta:
model = working
exclude = ('id')

view.py

# Create your views here.
from forms import *
from django import http
from django.shortcuts import render_to_response, get_object_or_404


def index(request):
  if request.method == "POST":
  form = WorkingForm(request.POST)
  if form.is_valid():
form.save()
return http.HttpResponse('Added')
  else:  
form = WorkingForm()
  return render_to_response('add_workingdays.html',locals())

Error Message:

ValueError at /

Cannot assign "u'x'": "working.w_name" must be a "Profile" instance.

Request Method: POST
Request URL:http://127.0.0.1:8000/
Django Version: 1.2.4
Exception Type: ValueError
Exception Value:

Cannot assign "u'x'": "working.w_name" must be a "Profile" instance.

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/
Django Version: 1.2.4
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'check']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/core/handlers/base.py"
 in get_response
  100. response = callback(request, *callback_args, 
**callback_kwargs)
File "/home/xyz/newapp/../newapp/check/views.py" in index
  10.   if form.is_valid():
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/forms/forms.py"
 in is_valid
  121. return self.is_bound and not bool(self.errors)
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/forms/forms.py"
 in _get_errors
  112. self.full_clean()
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/forms/forms.py"
 in full_clean
  269. self._post_clean()
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/forms/models.py"
 in _post_clean
  320. self.instance = construct_instance(self, self.instance, 
opts.fields, opts.exclude)
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/forms/models.py"
 in construct_instance
  51. f.save_form_data(instance, cleaned_data[f.name])
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/db/models/fields/__init__.py"
 in save_form_data
  416. setattr(instance, self.name, data)
File 
"/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg/django/db/models/fields/related.py"
 in __set__
  318.  self.field.name, 
self.field.rel.to._meta.object_name))

Exception Type: ValueError at /
Exception Value: Cannot assign "u'x'": "working.w_name" must be a "Profile" 
instance.


I did a foreign key relation between two tables and i am trying to insert 
the data to working table it get Cannot assign "u'x'": "working.w_name" must 
be a "Profile" instance.

if remove def *init*(self, *args, **kwargs): super(WorkingForm, 
self).*init*(*args, 
**kwargs) self.fields['w_name'] 
=forms.CharField(initial='x',widget=forms.HiddenInput())

it works normally,but i want to enter the username as hidden,but it throwing 
foreign key error



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Filtered drop down choice django

2011-01-31 Thread sushanth Reddy
I am trying to create a dynamic filtered drop down choice fields,i gone 
through below blog but it confusing,can any one suggest easy way to do this 
in django.

http://www.nerdydork.com/dynamic-filtered-drop-down-choice-fields-with-django.html

Thanks in advance :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Issue with Foriegnkey in django

2011-01-31 Thread sushanth Reddy
 

i AM trying to create a from which is linked with foriegnkey. 

Model.py

enter code here
model.py

class CreateD(models.Model):
id=models.IntegerField(primary_key=True)
db = models.CharField(max_length=50, blank=True)
iss  = models.CharField(max_length=100, blank=True)
status = models.CharField(max_length=2, blank=True ,default='A')
class Meta:
db_table = u'add_d'

def __unicode__(self):
return u'%s %s' % (self.db,self.iss)


class Assignment(models.Model):
id = models.IntegerField(primary_key=True)
assign_to = models.CharField(max_length=50, blank=True)
db_name = models.ForeignKey(CreateDb,related_name='set__dbname')
issue_type = models.ForeignKey(CreateDb,related_name='set_issuetype')
date = models.DateTimeField(null=True, blank=True)
class Meta:
db_table = u'assignment'
def __unicode__(self):
return u'%s %s' % (self.db_name,self.issue_type)

form.py

class AssignmentForm(ModelForm):

class Meta:
model = Assignment
exclude = ('id','date','assign_to')

assign.html 

   {{forms.as_p}}


Data in the sql :
   id  db iss
   1   A   AB
   2   B   BA




Output genrated from html page is 

   db_name: A AB (choice field)
B BA
   issue_type : A AB (choice field)
B BA


Actually i Need a output like below in html:

db_name: A (choice field)
 B 
   issue_type : AB (choice field)
BA

Please help me on this ...
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to write joins ?

2011-01-27 Thread sushanth Reddy
Thanks a ton sam...


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to write joins ?

2011-01-27 Thread sushanth Reddy
hi Sam,

Here is example model:

class Profile(models.Model):
 name = models.CharField(max_length=50, primary_key=True)
 assign = models.CharField(max_length=50)
 doj = models.DateField()
 dob = models.DateField()

 class Meta:
db_table = u'profile'

 def __str__(self):
 return  '%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)

 def __unicode__(self):
 return  u'%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)


class working(models.Model):
   w_name =models.ForeignKey(Profile, db_column='w_name')
   monday =  models.IntegerField(null=True, db_column='monday', blank=True)
   tuesday =  models.IntegerField(null=True, db_column='tuesday', 
blank=True)
   wednesday =  models.IntegerField(null=True, db_column='wednesday', 
blank=True)

   class Meta:
db_table = u'working'

   def __str__(self):
 return  '%s %s %s %s' % ( 
self.w_name,self.monday,self.tuesday,self.wednesday)

   def __unicode__(self):
 return  u'%s %s %s %s' % ( 
self.w_name,self.monday,self.tuesday,self.wednesday)

>>> m=working.objects.filter(w_name__name='sushanth')
>>> m.query.as_sql()
(u'SELECT `working`.`id`, `working`.`w_name`, `working`.`monday`, 
`working`.`tuesday`, `working`.`wednesday` FROM `working` WHERE 
`working`.`w_name` = %s ', ('sushanth',))
>>> 

But i am not getting any joins in above ...

any suggestions .



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to write joins ?

2011-01-27 Thread sushanth Reddy
HI,

How to write joins in django,i have gone through below django documentation 
,but joins are not working for my model

http://www.djangoproject.com/documentation/models/many_to_many/

http://docs.djangoproject.com/en/1.2/topics/db/queries/#lookups-that-span-relationships

and some blogs

My Model :


Class Profile(models.model)
 name = models.CharField(max_length=50, primary_key=True)
 assign = models.CharField(max_length=50)
 doj = models.DateField()
 dob = models.DateField()

 class Meta:
db_table = u'profile'

class __str__(self):
 return  '%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)

  class __unicode__(self):
 return  u'%s %s %s %s' % ( self.name,self.assign,self.doj,self.dob)


Class working(models.model)
  w_name =models.ForeignKey(Profile, db_column='name')
  monday =  models.IntegerField(null=True, db_column='monday', blank=True) 
  tuesday =  models.IntegerField(null=True, db_column='tuesday', blank=True)
  wednesday =  models.IntegerField(null=True, db_column='wednesday', 
blank=True) 

  class Meta:
db_table = u'working'

  lass __str__(self):
 return  '%s %s %s %s' % ( 
self.w_name,self.monday,self.tuesday,self.wednesday)

  class __unicode__(self):
 return  u'%s %s %s %s' % ( 
self.w_name,self.monday,self.tuesday,self.wednesday)


I am trying to do join between two tables profile and workingday

 like m=working.objects.filter(name='sushanth').select_related()


if i run above query i'll get 
  
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 129, 
in filter
return self.get_query_set().filter(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 498, 
in filter
return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 516, 
in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 
1675, in add_q
can_reuse=used_aliases)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 
1569, in add_filter
negate=negate, process_extras=process_extras)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 
1737, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'name' into field. Choices are:  monday,  
tuesday, wednesday,  w_name


I need to query where i can join working and profile.

support 

 select working.*,profile.assign,profile.doj from working join profile where 
name=w_name ;

I know django won't support joins,inner join  is also okay for me.

Can any one help on this.?






  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.