首页 > Linux操作系统 > Linux操作系统 > 用Django模型完成更多的任务


原创 Linux操作系统 作者:jieforest 时间:2012-06-07 04:50:37 0 删除 编辑
[i=s] 本帖最后由 jieforest 于 2012-6-7 04:50 编辑

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, 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!


from django.contrib.auth.models import User  
class NewUser(User):  
    class Meta.:  
        proxy = True  

来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录


  • 博文量
  • 访问量