How to paint mysql in the adminke django
Marcee last edited by
When I work with django 3 I use mysql.
I have a table mysql, the data in it should be added to the adminke. But I can't connect the table to hell.
As far as I'm concerned, we need to set up a model database and then register admin. But I couldn't find any example of what it did to MYSQL.
Tell me how to tie Mysql's table to the admin.
Thanks for the clue. I made a model class with the name of the right table. In the classroom, he wrote all the fields he needed according to the type of fields in mysql.
Further in the database, the current table has been added to the name of the prefix with the name of the annex in django. The name of the table was as follows: nameApp_nameClass. Where name App is the name of the application in Jango. nameClass is the class name in the model where all fields were declared.
And it really worked.
For example, I throw my class and the name of the table.
Table name - training_item. Django Annex - training.
Class in model.py:
class Item(models.Model): description = models.CharField(max_length=500, null=True) reps = models.CharField(max_length=50, null=True) sets = models.CharField(max_length=50, null=True) weight = models.CharField(max_length=45, null=True) rest_time = models.CharField(max_length=45, null=True) training = models.ForeignKey(List, on_delete=models.PROTECT) exercise = models.ForeignKey(Exercise, on_delete=models.PROTECT)
return self.training, '>>', self.exercise