M
M
Maxim2017-01-26 13:55:35
Django
Maxim, 2017-01-26 13:55:35

Is it possible to iterate over the fields of a django model?

Is it possible to iterate over a django model?
The bottom line is that I need to check which of the columns are not empty and make a dictionary out of them

class Message(models.Model):

    def __str__(self):
        return '%s %s %s %s %s' % (self.id, self.owner_id, self.text, self.files, self.timestamp)
    #owner = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
    owner_id = models.IntegerField(default=True)
    text = models.TextField(blank=True, max_length=10000)
    files = models.CharField(blank=True, max_length=1000)
    link = models.CharField(blank=True, max_length=1000)
    video = models.CharField(blank=True, max_length=1000)
    photo = models.CharField(blank=True, max_length=1000)
    options = models.CharField(blank=True, max_length=500)
    posts = models.IntegerField(default=0)

# что именно нужно
mes = Message.objects.get(owner_id=123)
# И итерировать mes

Is there such a possibility in django?

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