Filtering the filters in Django Admin

2011-02-19 Thread SimpleDimple
Here is my code for a school project
http://dpaste.com/434311/

The code works fine, on studentadmin list page, I get filter for
classes
which is good but as you can see my project is multi-tenant so in
filter
area I want to show only the classes for the school the current user
is
logged in (tracked thru sessions) but right now I can see list of all
classes from all schools

so I want to replace this line
list_filter   = ['xclass']

with something like
list_filter   =
Class.objects.filter(school=request.session['school_id'])

how can I do 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.



Re: Best forum/group for Django Help

2011-02-11 Thread SimpleDimple
agree on stackoverflow, not just for django but for many other
platforms too... I got a lot of help on rails and others there.

On Feb 10, 3:20 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Wednesday, February 9, 2011 9:06:54 PM UTC, SimpleDimple wrote:
>
> > Guys, Need to know which is the best forum/group for Django help ?  I
> > thought this is the one but I don't see much activity here despite of
> > the fact that there are 19000+ members...where do you go for
> > discussing your django issues with people ?
>
> No doubt I'm biased, but IMO StackOverflow is 
> excellent:http://stackoverflow.com/questions/tagged/django
> --
> DR.

-- 
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: Best forum/group for Django Help

2011-02-10 Thread SimpleDimple
Not a prank, it was just what I thought..., it is always better to ask
than assume...thanks for confirmation that this is the best one
around.

On Feb 10, 2:08 am, Shawn Milochik <sh...@milochik.com> wrote:
> On 02/09/2011 04:06 PM, SimpleDimple wrote:> Guys, Need to know which is the 
> best forum/group for Django help ?  I
> > thought this is the one but I don't see much activity here despite of
> > the fact that there are 19000+ members...where do you go for
> > discussing your django issues with people ?
>
> Is this a prank? This list is extremely active.
>
> There's also the #django IRC chat on freenode.
>
> Shawn

-- 
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.



Best forum/group for Django Help

2011-02-09 Thread SimpleDimple
Guys, Need to know which is the best forum/group for Django help ?  I
thought this is the one but I don't see much activity here despite of
the fact that there are 19000+ members...where do you go for
discussing your django issues with people ?

-- 
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: default header template file

2011-02-09 Thread SimpleDimple
ah... I see now...will check it out..

On Feb 9, 4:21 am, Shawn Milochik  wrote:
> The reason you should use the toolbar is that it will help you
> instantly determine which templates are being used, so you know which
> ones to edit.
>
> Shawn

-- 
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 Populate A Dropdown List

2011-02-09 Thread SimpleDimple
did it work Hank ?

On Feb 9, 7:47 am, Brian Neal  wrote:
> On Feb 8, 10:03 am, hank23  wrote:
>
> > I have coded a form which will display some data in a dropdown
> > selection box. The data is being populated from a a queryset that I
> > have setup in the form's code. However the entries in the dropdown
> > only display as objects of the table from which they're being
> > retrieved, and don't display the actual field data that I was hoping
> > to have it display. So how do I specify in the form which of the table
> > fields is to be the display field and which is suppoed to be the
> > underying key value to be passed when and entry is selected? Thanks
> > for the help.
>
> Post your code somewhere, e.g. dpaste.com so we have a better idea
> what you are trying to do.
>
> Best,
> BN

-- 
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: Setting session variable at the time of login

2011-02-09 Thread SimpleDimple
This is great, I'll definitely look into this weekend...and get back
to you.

On Feb 9, 11:37 pm, Matteius <matte...@gmail.com> wrote:
> You may be interested in this school system 
> django-classcomm:http://classcomm.googlecode.com/  demoed 
> athttp://classcomm.net/ I
> am the primary developer on this and I have JIRA project management
> and product backlog etc. so perhaps you would be more interested in
> working off an existing system.
>
> On Feb 7, 2:42 pm, SimpleDimple <farhandevelo...@gmail.com> wrote:
>
> > I am new to django and building a school system but am experience
> > developer otherwise having firm grip over rails, php, .net and java.
>
> > 1) I am using django admin, I want to set a variable at the time of
> > user login... the user login is coming from django code so I have no
> > idea how to capture "after login" eventplease help.
>
> > 2) Also is it easy to add/control/manage more fields to django's auto
> > generated user profile ? or what is best practice 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: How To Populate A Dropdown List

2011-02-08 Thread SimpleDimple
I am new to django so not sure if I am of much help but let me try

the key is usually the ID field of your table.
for the value to display add a method __str___ in your model, here is
sample code from one of my project
read more on ___str___ and ___unicode___ methods


class Teacher(models.Model):
school= models.ForeignKey("School")
xclass= models.ForeignKey("Class", verbose_name='Class')
name  = models.CharField("Teacher Name",max_length=50)

def __str__(self):
   return self.name


On Feb 8, 9:03 pm, hank23  wrote:
> I have coded a form which will display some data in a dropdown
> selection box. The data is being populated from a a queryset that I
> have setup in the form's code. However the entries in the dropdown
> only display as objects of the table from which they're being
> retrieved, and don't display the actual field data that I was hoping
> to have it display. So how do I specify in the form which of the table
> fields is to be the display field and which is suppoed to be the
> underying key value to be passed when and entry is selected? Thanks
> for the 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: Filtering List based on a custom dropdown

2011-02-08 Thread SimpleDimple
can anyone help or point me to some simple django based app that I can
study to understand more ?

On Feb 8, 2:07 am, SimpleDimple <farhandevelo...@gmail.com> wrote:
> I can live w/o AJAX for now to keep it simple.
>
> What I am not clear is on how to do the postback from javascript ?  I
> mean on what URL and pass on which variables ? and thru GET or POST or
> shall i do form.submit()  ??
>
> On Feb 8, 1:45 am, Joel Goldstick <joel.goldst...@gmail.com> wrote:
>
> > On Mon, Feb 7, 2011 at 3:38 PM, SimpleDimple 
> > <farhandevelo...@gmail.com>wrote:
>
> > > I am new to django and building a school system but am experience
> > > developer otherwise having firm grip over rails, php, .net and java.
>
> > > I have student table and in list I can see list of all students/
> > > records in student table(pasted below is my code)
>
> > > what I want here is a custom dropdown listing the classes in school
> > > from class table, and when you select/change the class the list of
> > > students should get filtered accordinglycan someone please give me
> > > hints or guide me a bit ?
>
> > > class StudentAdmin(admin.ModelAdmin):
> > >    fields        = ['xclass', 'name', 'reg_no' , 'roll_no' ]
> > >    list_display  = ['xclass', 'name', 'reg_no' , 'roll_no' ]
> > >    list_filter   = ['name', 'reg_no' , 'roll_no' ]
> > >    search_fields = ['name', 'reg_no' , 'roll_no' ]
>
> > >    form          =  StudentForm
>
> > >    def queryset(self, request):
> > >        school_id = request.session['school_id']
> > >        qs = self.model._default_manager.filter(school=school_id)
> > >        return qs
>
> > >    def save_model(self, request, obj, form, change):
> > >        school_id = request.session['school_id']
> > >        school = School.objects.get(id=school_id)
> > >        obj.school = school
> > >        obj.save()
>
> > > --
> > > 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.
>
> > This topic has come up recently under different specifics.  When you change
> > your filter (by selecting a specific class) you need to requery with that
> > condition.  This can be done by submitting the form to get a new dataset, or
> > by using AJAX style to have the data retrieved on the fly to repopulate your
> > form.
>
> > --
> > Joel Goldstick

-- 
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: default header template file

2011-02-08 Thread SimpleDimple
Thanks for the link but actually I am not looking for debugging, I
just want to add up my own stuff into the header coming from DBcan
you help me in that ?



On Feb 8, 2:08 am, Shawn Milochik  wrote:
> This will help you a lot:
>
> https://github.com/robhudson/django-debug-toolbar
>
> It shows you the templates being used and a bunch of other stuff.
>
> Shawn

-- 
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: Setting session variable at the time of login

2011-02-08 Thread SimpleDimple
Great Pointer - I think this is what I was looking for.

On Feb 8, 2:13 am, Shawn Milochik  wrote:
> 1. You'll have to create your own login view. You can look at Django's
> view and just copy it. You can use the built-in authentication and
> template and everything, plus whatever else you want to do.
>
> 2. Here's how you do 
> that:http://docs.djangoproject.com/en/1.2/topics/auth/#storing-additional-...

-- 
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: Sorting list view on based on field from joined table

2011-02-08 Thread SimpleDimple
I understand the model part, I am more concerned about

1) how and which event to capture on server side when header is
clicked
2) how to know which column's header was clicked

Can you please help.

On Feb 8, 2:36 am, Aryeh Leib Taurog <v...@aryehleib.com> wrote:
> On Feb 7, 10:50 pm, SimpleDimple <farhandevelo...@gmail.com> wrote:
>
> > I am new to django and building a school system but am experience
> > developer otherwise having firm grip over rails, php, .net and java.
>
> > I can see the list and do sorting & search but only based on the
> > fields which are in the same table... what if I want to sort on or
> > search on field which is in another table ? something like
>
> > select class.* from class, session
> >    where class.session_id = session.id
> >    order by session.starting_date
>
> Class.objects.order_by(session__starting_date)
>
> see docs for order_by method of 
> QuerySethttp://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by

-- 
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: Getting value from session in ModelForm

2011-02-08 Thread SimpleDimple
I understand what you mean about the scope

Thanks for the sample code, very helpful, will try it out and let you
know.

Thanks,

On Feb 8, 2:45 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Monday, February 7, 2011 8:27:55 PM UTC, SimpleDimple wrote:
>
> > I am new to Django and building a school system but am an experienced
> > developer otherwise having firm grip over rails, .net, php & java.
>
> > I have the following class where on teacher add/edit form, I am trying
> > to filter values in class drop down based on school.  The value of
> > school_id is saved in session but as you can see below pulling value
> > from session fails in ModelForm, can someone please guide me on how to
> > get the value from session here ?
>
> > class TeacherForm(ModelForm):
> >     def __init__(self, *args, **kwargs):
> >         super(TeacherForm, self).__init__(*args, **kwargs)
> >         xclass = self.fields['xclass'].widget
>
> >         choices = []
>
> >         #school_id = request.session['school_id']     # since this
> > fails, I have hard coded the value 2 in line below for now
> >         school_id = 2
> >         xclasses = Class.objects.filter(school=school_id)
> >         for c in xclasses:
> >             choices.append((c.id,c.name))
> >         xclass.choices = choices
>
> It's fundamental to Python programming generally - and, I would have
> thought, Java and Ruby (although not PHP) - that if you want access to an
> object in a scope, you need to pass it into that scope. In order for you to
> access request.session within that __init__ method, you'll need to
> explicitly make the request object available there, which means passing it
> in when you initialise the form.
>
> I usually do it like this:
>
>     class MyForm(forms.ModelForm):
>         def __init__(self, *args, **kwargs):
>             request = kwargs.pop('request')
>             super(TeacherForm, self).__init__(*args, **kwargs)
>             ...etc...
>
> now initialise the form in your view:
>
>     form = MyForm(request=request)
>
> --
> DR.

-- 
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: Filtering List based on a custom dropdown

2011-02-07 Thread SimpleDimple
I can live w/o AJAX for now to keep it simple.

What I am not clear is on how to do the postback from javascript ?  I
mean on what URL and pass on which variables ? and thru GET or POST or
shall i do form.submit()  ??


On Feb 8, 1:45 am, Joel Goldstick <joel.goldst...@gmail.com> wrote:
> On Mon, Feb 7, 2011 at 3:38 PM, SimpleDimple <farhandevelo...@gmail.com>wrote:
>
>
>
> > I am new to django and building a school system but am experience
> > developer otherwise having firm grip over rails, php, .net and java.
>
> > I have student table and in list I can see list of all students/
> > records in student table(pasted below is my code)
>
> > what I want here is a custom dropdown listing the classes in school
> > from class table, and when you select/change the class the list of
> > students should get filtered accordinglycan someone please give me
> > hints or guide me a bit ?
>
> > class StudentAdmin(admin.ModelAdmin):
> >    fields        = ['xclass', 'name', 'reg_no' , 'roll_no' ]
> >    list_display  = ['xclass', 'name', 'reg_no' , 'roll_no' ]
> >    list_filter   = ['name', 'reg_no' , 'roll_no' ]
> >    search_fields = ['name', 'reg_no' , 'roll_no' ]
>
> >    form          =  StudentForm
>
> >    def queryset(self, request):
> >        school_id = request.session['school_id']
> >        qs = self.model._default_manager.filter(school=school_id)
> >        return qs
>
> >    def save_model(self, request, obj, form, change):
> >        school_id = request.session['school_id']
> >        school = School.objects.get(id=school_id)
> >        obj.school = school
> >        obj.save()
>
> > --
> > 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.
>
> This topic has come up recently under different specifics.  When you change
> your filter (by selecting a specific class) you need to requery with that
> condition.  This can be done by submitting the form to get a new dataset, or
> by using AJAX style to have the data retrieved on the fly to repopulate your
> form.
>
> --
> Joel Goldstick

-- 
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.



default header template file

2011-02-07 Thread SimpleDimple
I am new to django and building a school system but am experience
developer otherwise having firm grip over rails, php, .net and java.

When I login, I can see the username of user logged-in in the
header... I want to add more info from sessions there, so I am
wondering which template file is it for header ?

-- 
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.



Sorting list view on based on field from joined table

2011-02-07 Thread SimpleDimple
I am new to django and building a school system but am experience
developer otherwise having firm grip over rails, php, .net and java.

I can see the list and do sorting & search but only based on the
fields which are in the same table... what if I want to sort on or
search on field which is in another table ? something like

select class.* from class, session
   where class.session_id = session.id
   order by session.starting_date

-- 
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.



Setting session variable at the time of login

2011-02-07 Thread SimpleDimple
I am new to django and building a school system but am experience
developer otherwise having firm grip over rails, php, .net and java.

1) I am using django admin, I want to set a variable at the time of
user login... the user login is coming from django code so I have no
idea how to capture "after login" eventplease help.

2) Also is it easy to add/control/manage more fields to django's auto
generated user profile ? or what is best practice 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.



Filtering List based on a custom dropdown

2011-02-07 Thread SimpleDimple
I am new to django and building a school system but am experience
developer otherwise having firm grip over rails, php, .net and java.

I have student table and in list I can see list of all students/
records in student table(pasted below is my code)

what I want here is a custom dropdown listing the classes in school
from class table, and when you select/change the class the list of
students should get filtered accordinglycan someone please give me
hints or guide me a bit ?



class StudentAdmin(admin.ModelAdmin):
fields= ['xclass', 'name', 'reg_no' , 'roll_no' ]
list_display  = ['xclass', 'name', 'reg_no' , 'roll_no' ]
list_filter   = ['name', 'reg_no' , 'roll_no' ]
search_fields = ['name', 'reg_no' , 'roll_no' ]

form  =  StudentForm

def queryset(self, request):
school_id = request.session['school_id']
qs = self.model._default_manager.filter(school=school_id)
return qs

def save_model(self, request, obj, form, change):
school_id = request.session['school_id']
school = School.objects.get(id=school_id)
obj.school = school
obj.save()


-- 
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.



Getting value from session in ModelForm

2011-02-07 Thread SimpleDimple
I am new to Django and building a school system but am an experienced
developer otherwise having firm grip over rails, .net, php & java.

I have the following class where on teacher add/edit form, I am trying
to filter values in class drop down based on school.  The value of
school_id is saved in session but as you can see below pulling value
from session fails in ModelForm, can someone please guide me on how to
get the value from session here ?


class TeacherForm(ModelForm):
def __init__(self, *args, **kwargs):
super(TeacherForm, self).__init__(*args, **kwargs)

xclass = self.fields['xclass'].widget

choices = []

#school_id = request.session['school_id'] # since this
fails, I have hard coded the value 2 in line below for now
school_id = 2
xclasses = Class.objects.filter(school=school_id)
for c in xclasses:
choices.append((c.id,c.name))
xclass.choices = choices

-- 
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.