M
M
Mooris2017-04-28 16:27:03
Django
Mooris, 2017-04-28 16:27:03

Django, how to display a button to automatically write to a table?

Hello, I'm new to Django, I need help on how to display a button next to each ClientAdmin list_display line that automatically writes data to the Jurnal table, i.e. for example, a client came > clicked the button > and for this client they signed up in the Jurnal table
, there are models

class Client(models.Model):
    client_id = models.AutoField(primary_key=True)
    client_name = models.CharField(max_length=30, blank=True, null=True)
    client_familia = models.CharField(max_length=30, blank=True, null=True)
    pol = models.CharField(max_length=1, choices=POL)

class Jurnal(models.Model):
    poseshenie = models.AutoField(unique=True, primary_key=True)
    client = models.ForeignKey(Client, models.DO_NOTHING, blank=True, null=True)
    data_poseshenia = models.DateField(blank=True, null=True)
    time_poseshenia = models.TimeField(blank=True, null=True)

something like this, something should work out, that is, by clicking automatically write the time to the Jurnal table, then this particular client
came admin.py
class ClientAdmin(admin.ModelAdmin):
   class ClientAdmin(admin.ModelAdmin):
    list_display = ('client_id', 'client_name', 'client_familia', 'time_poseshenia', 'button')

    def button (self, obj)
          ....

a new record is created, this is a separate customer accounting model, they are added independently by the administrator
d77bd489d9b6461a8ea2c31f8ce811f9.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question