I've been trying doing this: class ArticuloTallaInline(admin.TabularInline): model = Articulo_Talla extra = 0
def get_formset(self, request, obj=None, **kwargs): self.padre = obj return super(ArticuloTallaInline, self).get_formset(request, obj, **kwargs) def formfield_for_foreignkey(self, db_field, request, **kwargs): print self.padre.tallaje if db_field.name == "talla": kwargs["queryset"] = Talla.objects.filter(tallaje=1) return super(ArticuloTallaInline, self).formfield_for_foreignkey(db_field, request, **kwargs) It shows me value of tallaje in parent form but I got an Exception Value: 'NoneType' object has no attribute 'tallaje' My idea is do something like this: kwargs["queryset"] = Talla.objects.filter(tallaje=self.padre.tallaje) but it doesn't work. Thanks. On 23 mar, 14:51, bernatbonet <bernatbo...@gmail.com> wrote: > Hi, I've been trying to solve one probleme, and I'll explain what I > want to do. > > First I'll show my models; > > class Tallaje(models.Model): > cod = models.CharField(max_length=5) > desc = models.CharField(max_length=60) > > class Talla(models.Model): > tallaje = models.ForeignKey('Tallaje') > cod = models.CharField(max_length=5) > desc = models.CharField(max_length=60) > > class Articulo(models.Model): > ref = models.CharField(max_length=15) > tallaje = models.ForeignKey('Tallaje') > > class Articulo_Talla(models.Model): > articulo = models.ForeignKey('Articulo') > talla = models.ForeignKey('Talla') > > And my admin.py file: > > class ArticuloTallaAdmin(admin.TabularInline): > model = Articulo_Talla > extra = 0 > > class ArticuloAdmin(admin.ModelAdmin): > list_display = ('ref',) > list_filter = ('ref',) > ordering = ('ref',) > search_fields = ('ref',) > fieldsets = ( > (None, {'fields': ('ref', 'tallaje')}), > ) > inlines = [ArticuloTallaAdmin] > > I want to filter talla select from inline form by the value selected > in parent field tallaje. > Every time I change tallaje in parent, tallas in inline form must be > queryset changed. > > I don't know if this can be done in admin.py or I must do it in > javascript, and I want to know where to start. > > Thanks a lot. -- 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.