#15355: Choices on ForeignKey in Inlines not limited to the model constraints
------------------------------------------------+---------------------------
               Reporter:  Stan                  |         Owner:  nobody        
         
                 Status:  reopened              |     Milestone:                
         
              Component:  django.contrib.admin  |       Version:  1.3-beta      
         
             Resolution:                        |      Keywords:  inline 
foreignkey admin
           Triage Stage:  Unreviewed            |     Has patch:  0             
         
    Needs documentation:  0                     |   Needs tests:  0             
         
Patch needs improvement:  0                     |  
------------------------------------------------+---------------------------
Changes (by Stan):

  * status:  closed => reopened
  * resolution:  invalid =>


Comment:

 Many thanks Ramiro for reviewing the bug.

 There is an error in the models I have posted above : the second FK
 (address) in {{{ EmailAdvertisorInline }}} is for {{{ AdvertisorOffice.
 }}}
 I have attached a small Django project with fixtures (admin:admin) and
 some screenshots to illustrate the case.

 In advertisor1.png you can see an advertisor having 2 offices. In
 advertisor2.png, in the Email's inlines, the Advertisor1's offices are
 present.

 Here the working models.py :

 {{{
 from django.db import models
 from django.contrib.sites.models import Site, SiteManager


 class Support(Site):
     short_name = models.CharField(max_length=10)
     logo = models.ImageField('logo', upload_to='images/supports',
 blank=True)
     objects = SiteManager()


 class Address(models.Model):
     name = models.CharField(max_length=200, blank=True)
     memo = models.CharField(max_length=50)
     short_name = models.CharField(max_length=200, null=True, blank=True)
     address = models.CharField(max_length=200, blank=True)

     class Meta:
         abstract = True

     def __unicode__(self):
         return '%s' % self.memo


 class Advertisor(Address):
     euid = models.IntegerField(blank=True, null=True)
     login = models.CharField(max_length=30, unique=True)
     password = models.CharField(max_length=30, blank=True)


 class AdvertisorOffice(Address):
     name_selected = models.BooleanField('')
     short_name_selected = models.BooleanField('')
     address_selected = models.BooleanField('')
     advertisor = models.ForeignKey(Advertisor)


 TYPE_EMAIL_CHOICES = (
     ('BAT', 'BAT'),
 )


 class EmailAdvertisor(models.Model):
     advertisor = models.ForeignKey(Advertisor)
     address = models.ForeignKey(AdvertisorOffice, blank=True, null=True)
     support = models.ForeignKey(Support, blank=True, null=True)
     email_type = models.CharField('type', max_length=10,
 choices=TYPE_EMAIL_CHOICES, default='BAT')
     email = models.EmailField()

 }}}

 And the admin.py :

 {{{
 from django.contrib import admin
 from bug_15355.myapp import models


 class AdvertisorOfficeInline(admin.StackedInline):
     model = models.AdvertisorOffice
     extra = 0
     can_delete = False
     fieldsets = (
         (None, {
                 'fields': (('memo',),
                            ('name_selected', 'name'),
                            ('short_name_selected', 'short_name'),
                            ('address_selected', 'address')),
                 'description': 'Select to override the advertisor data.'
                 }),
         )


 class EmailAdvertisorInline(admin.TabularInline):
     model = models.EmailAdvertisor
     extra = 1

 class AdvertisorAdmin(admin.ModelAdmin):
     fieldsets = (
         (None, {
             'fields': (('memo',),
                        ('name', 'short_name',),
                        'address'),
             }),
         ('Authentification', {
             'fields': ('login', 'password')
             }),
         )
     inlines = [
         AdvertisorOfficeInline,
         EmailAdvertisorInline,
     ]


 admin.site.register(models.Support)
 admin.site.register(models.Advertisor, AdvertisorAdmin)

 }}}


 Thanks.

 ps : If you need manpower to investigate, just let me know.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15355#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to