I have two models, Client and PaymentOptions.
class Client(models.Model):
name = models.CharField(max_length=50, null=True, unique=False)
contact = models.CharField(max_length=50, null=True, unique=False)
address = models.CharField(max_length=300, null=True, unique=False)
class ClientPaymentOption(models.Model):
name = models.CharField(max_length=30, null=True, unique=False, choices=CARD_TYPE)
action = models.CharField(max_length=30, null=True, unique=False, choices=CLIENT_PAYMENT_OPTION)
percent = models.FloatField(max_length=10, null=True, unique=False)
fixamount = models.FloatField(max_length=20, null=True, unique=False)
itemcharged = models.CharField(max_length=10, null=True, unique=False)
In my admin.py, I just want to have when I create a new Client, it will also create it’s ClientPaymentOption.
I have this in my admin.py:
admin.site.disable_action('delete_selected')
class ClientAdmin(admin.ModelAdmin):
#display list
list_display = ('name','b_type','banner','logo',
'contact','address','account_type',
'status','currency','color','user',
)
#display fields
fields = ('name','b_type','banner','logo','contact',
'address','account_type','status',
'currency','color','user',
)
pass
admin.site.register(Client, ClientAdmin)
I have done this in my views.py,
client = Client.objects.create( .... )
ClientPaymentOption.objects.create( ...., client=client )
but i dont have any idea to do this in django admin.
do anyone have an idea about my situation? thanks in advance …
You can override standard django-admin change_view and add
ClientPaymentOption.objects.create( ...., client=client )there.
A short example from django docs: