So you have a Django app, but sometimes you find the Django models too constraining. We will guide you through using Django models to get more out of them. This is an intermediate tutorial, as some familiarity with Django is assumed. For example, we assume you know how to write a basic Django model, you know how to override Python methods, as well as how .filter and.exclude work.
We will talk about these topics
1. Proxy Models
2. Overriding .save
3. Using signals
4. Optimizing your DB access using .extra
5. Advanced lookups using Q objects
6. Aggregation and Annotation
7. Using F() expressions
Lets look at some common operations you may want to perform. using Django and how the above Django functionality will help you achieve them.
How can I get two Python representation of the same Database table?
You may want to have two model classes corresponding to a single database table. For example, admin.site.register allows a Model to be registered only once. However, you may want the same model twice in the Admin area. Proxy models can help you do that!
CODE:from django.contrib.auth.models import User
来自 “ ITPUB博客 ” ，链接：http://blog.itpub.net/301743/viewspace-732101/，如需转载，请注明出处，否则将追究法律责任。