tabla queryset plantilla modelos girls girl formulario form example dinamica data django django-models django-admin django-forms

queryset - render data django



¿Cómo puedo darle a `def formfield_for_manytomany` una identificación de objeto editable (1)

Suponiendo que está buscando la instancia de Report editada por ReportAdmin , intente esto:

class ReportAdmin(admin.ModelAdmin): def get_object(self, request, object_id): # Hook obj for use in formfield_for_manytomany self.obj = super(ReportAdmin, self).get_object(request, object_id) print "Got object:", self.obj return self.obj def formfield_for_manytomany(self, db_field, request, **kwargs): if db_field.name == "r_precursor" and getattr(self, ''obj'', None): kwargs["queryset"] = Precursor.objects.filter( ops_area=self.obj.ops_area) return super(ReportAdmin, self).formfield_for_manytomany( db_field, request, **kwargs)

class Report(models.Model): precursor = models.ManyToManyField(Precursor) class ReportAdmin(admin.ModelAdmin): def formfield_for_manytomany(self, db_field, request, **kwargs): ops_area = Report.objects.get(id=???????).ops_area print id print ops_area if db_field.name == "r_precursor": kwargs["queryset"] = Precursor.objects.filter(ops_area=ops_area) print kwargs return super(ReportAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)

¿Cómo puedo dar def formfield_for_manytomany una identificación de objeto editable?