Login

Tag "instance"

Snippet List

create_model_instances management command

This management command is run like this: `./manage.py -a someapp filename.cfg` it looks in `someapp`'s directory for a file called `/config/filename.cfg` with the format explained in the help text, and creates the model instances described in the config file. It uses the configobj module. this would be an example config file: [project.Profile] [[fields]] receive_notifications = False [[children]] [[[auth.User]]] [[[[fields]]]] username = AnnonymousUser password = ! # set unusable password. There's no way yet to hash and set a given password email = [email protected]

  • model
  • instance
  • object-creation
  • config-file
Read More

Dump a model instance and related objects as a Python data structure

This utility makes a text dump of a model instance, including objects related by a forward or reverse foreign key. The result is a hierarchical data structure where * each instance is represented as a list of fields, * each field as a (<name>, <value>) tuple, * each <value> as a primitive type, a related object (as a list of fields), or a list of related objects. See the docstring for examples. We used this to make text dumps of parts of the database before and after running a batch job. The format was more useful than stock `dumpdata` output since all related data is included with each object. These dumps lend themselves particularly well for comparison with a visual diff tool like [Meld](http://meldmerge.org/).

  • serialize
  • dump
  • model
  • instance
Read More

Update timestamp If any instance field has changed

Needed a function to check if any field in an instance has changed. If so update a datetime field to now to keep track of changes. This function is an override of the save function in the model.

  • fields
  • model
  • save
  • field
  • method
  • instance
  • override
  • compare
Read More

3 snippets posted so far.