Monday, October 27, 2014

pre-populate tabular inline in admin

Hi, i need pre-populete tabular inline in admin what is the best ways
example

class Options(models.Model):
     name = CharField(...)


class ModelA(models.Model):
    option = FK(Options)
    field_1 = IntegerField()
    field_2 = IntegerField()
    field_3 = CharField()
    field_4 = booleanField()

in forms.py
class ModelAForm(ModelForm):
    class Meta:
         model = ModelA

ModelAFormSet = formsets.formset_factory(ModelAForm, extra=Option.objects.count())

#but I do not understand when to use initial

in admin.py
extra_count = Options.objects.all().count()

class ModelAInline(admin.TabularInline)
    model = ModelA
    formset = ModelAFormSet
    extra = extra_count
    max_num = extra_count


but i don't understand complete, i need my admin equal this
i have 4 Option in my class Options

option      field_1     field_2     field_3     field_4
--------------------------------------------------------------
option1      __           __            __           ___
option2      __           __            __           ___
option3      __           __            __           ___
option4      __           __            __           ___

i don't need add another !

I need all deployed only introduce additional data field_x (1,2,3,4)

as I can do this in the admin ??

any link? example? idea?

Cheers




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM-7rO3tBFkvu_Z3%3DcuR6KoS_qz%2BVc3GgT7fR5UoDCGfTFZxgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment