Filtering model results for Django admin select box -


I am just starting playing with Django today and so far it is not difficult to do simple things. What I'm struggling with is the StatusTypes model that is filtering a list of status types:

StatusTypes (models.Model): Status = models.CharField (MAX_LENGTH = 50 ) Type = models.IntegerField () DEF __unicode __ (self): return self.status class meta: db_table = u'status_types'

In an admin page I need all the results where Type = 0 and in the second, I will need all the results where type = 1 so I do not restrict it from within the model And I would know about it?

Edit: I should have been a bit clearer. I have a model "unit" in which there is a foreign key for StatStamps, the I models are as follows:

  class StatusTypes (models.Model): position = models.CharField (MAX_LENGTH = 50) type = models.IntegerField () DEF __unicode __ (self): returning self. Position class meta: db_table = u'status_types' square unit (models.Model): name = models.CharField (unique = true, MAX_LENGTH = 50) status = models.ForeignKey (StatusTypes, db_column = 'position') Note = Models . TextField () DATE_ADDED = models.DateTimeField () Def __unicode __ (self): return self.name class meta: db_table = u'units'  

So now the administrator for the unit model page I I want to limit the position with only those people who are with Type = 1, I have tried the following code based on the laserscience response given below:

  inv.intonory Model unit django.contrib import administrator to class unit admin (admin.model admin): Def Quarreets ( Wyn, request): QS = (Super Unit Admin, self). Choirset (Request) returns qs.filter (Type = 0) Admin.site.register (Unit, UnitAdmin)  

But, this selection box does not change at all. I also tried to print the value of QS and nothing had been output to my terminal, so I was thinking that I have some calls in the form of satcos?

Edit 2: It is clear that I want to filter it for the Status dropdown on the Unit model creation page.

"post-text" itemprop = "text">

Edit:

It has been found that ModelAdmin.formfield_for_foreignkey was the correct answer in this situation:

Previous Answer:

Take a look at what it looks like what you want from me, because it will make a nice interface to filter on different criteria instead of restricting your query .


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -