Вопрос по python – Печать объектов в Джанго

11

Error: User Rate Limit Exceededfrom myapp.models import ArtistError: User Rate Limit Exceededprint Artist.objects.all()[:5]Error: User Rate Limit Exceeded

[<Artist: Artist object>, <Artist: Artist object>, <Artist: Artist object>, <Artist: Artist object>, <Artist: Artist object>]

Error: User Rate Limit Exceeded

Ваш Ответ

3   ответа
0

unicode

 def __unicode__(self):
    return u'%s' % (self.id)

class unit(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
def __unicode__(self):
    return u'%s' % (self.name)

print(unit.objects.all())
[unit: KG, unit: PCs]
Error: User Rate Limit ExceededunitError: User Rate Limit Exceeded[unit: KG, unit: PCs]Error: User Rate Limit ExceededA from KG B from PCsError: User Rate Limit ExceededA, BError: User Rate Limit ExceededKG, PCError: User Rate Limit Exceededunit.
Error: User Rate Limit Exceeded
6

UPDATE:Error: User Rate Limit ExceededPython 3.xError: User Rate Limit Exceeded__str__Error: User Rate Limit Exceeded__unicode__

Error: User Rate Limit Exceeded__unicode__Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Gabe C.
16

>>> class MyObject(object):
...     pass
... 
>>> [MyObject(), MyObject()]
[<__main__.MyObject object at 0x0480E650>,
 <__main__.MyObject object at 0x0480E350>]

values.

# This list contains a Blog object.
>>> Blog.objects.filter(name__startswith='Beatles')
[<Blog: Beatles Blog>]

# This list contains a dictionary.
>>> Blog.objects.filter(name__startswith='Beatles').values()
[{'id': 1, 'name': 'Beatles Blog', 'tagline': 'All the latest Beatles news.'}]
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Gabe C.
Error: User Rate Limit Exceededvalues()Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы