V
V
Vitaly Ananiev2022-03-28 22:40:03
Django
Vitaly Ananiev, 2022-03-28 22:40:03

How to add any information to the already existing attributes in the model in the database in views.py?

Let's say I have a model

class Customer(models.Model):
    user = models.ForeignKey(User, verbose_name='Пользователь', on_delete=models.CASCADE, blank=True, null=True,
                             max_length=25)
    avatar = models.ImageField("Аватар", upload_to="photos/%Y/%m/%d", default='photos/profile.png', blank=True)
    date = models.DateField("Дата создания", auto_now=False, auto_now_add=True, blank=True, null=True)

And there are already user = Vitalii, Vladimir in the database...
And I want to write logic in views.py to add a photo to the avatar field if user == Vitalii(update photo)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-03-29
@Vitalii181190

Open the documentation and read how to edit the model from views

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question