1π
β
You can restrict the inline fields like this (ofcourse you still need the form to validate, you could use javascript or default values to set gaps)
class MyModelInline(admin.TabularInline):
model = MyModel
fields = ["x", "y", "z"]
#fk_name = "..."
#max_num = 1
#extra = 0
0π
If you want to show proper text for βBβ in choice field, in your model B
add __unicode__
method and return string using fields of B
,
eg.
class B(models.Model):
a = models.IntegerField(...)
b = models.CharField(...)
c = models.BooleanField(...)
def __unicode__(self):
return u''+str(self.a) + ':' + self.b
π€Rohan
- [Answer]-Django-multiuploader: failed to find libmagic
- [Answer]-Django Url error: invalid literal for int() with base 10: "python"
- [Answer]-Django : Error: No module named apps β Django version 1.4.5
0π
inlineformset_factory
accepts form
argument, which is a modelform class for your βBβ objects. So, defining a form class with fields = ('a', 'b')
in Meta
and passing it to the function should help.
π€uruz
- [Answer]-How to add the current time?
- [Answer]-Override ForeignKey relationship in child model?
- [Answer]-Django Queries to return a specific set of items
- [Answer]-How to save JSON from Vk.com API response to MongoDB?
Source:stackexchange.com