Django for Designers/Adding models: Difference between revisions

imported>Aldeka
imported>Aldeka
Line 566:
 
<source lang="python">
>>> importfrom bookmarks.models import Bookmark, Tag
>>> import random
>>> tag_names = ['kids', 'read_on_plane', 'send_to_mom']
>>> # Create the Tag objects
>>> for tag_name in tag_names:
... tag = bookmarks.models.Tag(slug=tag_name)
... tag.save()
...
>>> kids_urls = ['http://pbskids.org/', 'http://www.clubpenguin.com/', 'http://www.aplusmath.com/hh/index.html', 'http://kids.nationalgeographic.com/kids/activities/recipes/lucky-smoothie/', 'http://www.handwritingforkids.com/', 'http://pinterest.com/catfrilda/origami-for-kids/', 'http://richkidsofinstagram.tumblr.com/', 'http://www.dorkly.com/picture/50768/', 'http://www.whyzz.com/what-is-paint-made-of', 'http://yahooligans.com/']
>>> for kids_url in kids_urls:
... b = bookmarks.models.Bookmark(author=me, url=kids_url)
... b.save()
... how_many_tags = random.randrange(len(tag_names))
Line 582:
... b.tag_set.add(bookmarks.models.Tag.objects.get(slug=tag_name))
...
>>> b = bookmarks.models.Bookmark.objects.get(url='http://yahooligans.com/')
>>> b.title = "Yahoooo!!!!!ligans"
>>> b.save()
Anonymous user