Changeset 3096
- Timestamp:
- 06/06/06 22:10:28 (2 years ago)
- Files:
-
- django/trunk/docs/db-api.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/db-api.txt
r3092 r3096 716 716 created. 717 717 718 This is meant as a shortcut to boilerplatish code. For example:: 718 This is meant as a shortcut to boilerplatish code and is mostly useful for 719 data-import scripts. For example:: 719 720 720 721 try: … … 748 749 use the result as the keyword arguments to the model class. 749 750 750 Finally, if you have a field named ``defaults`` and want to use it as an exact 751 lookup in``get_or_create()``, just use ``'defaults__exact'``, like so::751 If you have a field named ``defaults`` and want to use it as an exact lookup in 752 ``get_or_create()``, just use ``'defaults__exact'``, like so:: 752 753 753 754 Foo.objects.get_or_create(defaults__exact='bar', defaults={'defaults': 'baz'}) 755 756 Finally, a word on using ``get_or_create()`` in Django views. As mentioned 757 earlier, ``get_or_create()`` is mostly useful in scripts that need to parse 758 data and create new records if existing ones aren't available. But if you need 759 to use ``get_or_create()`` in a view, please make sure to use it only in 760 ``POST`` requests unless you have a good reason not to. ``GET`` requests 761 shouldn't have any effect on data; use ``POST`` whenever a request to a page 762 has a side effect on your data. For more, see `Safe methods`_ in the HTTP spec. 763 764 .. _Safe methods: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1 754 765 755 766 ``count()``
