app_models package¶
Subpackages¶
- app_models.migrations package
- Submodules
- app_models.migrations.0001_initial module
- app_models.migrations.0002_category_orderdetail_product_subuserorder_supplier_userorder_warehouse module
- app_models.migrations.0003_userrole module
- app_models.migrations.0004_userasset module
- app_models.migrations.0005_fulluserinfo module
- app_models.migrations.0006_proxytoken module
- app_models.migrations.0007_delete_proxytoken module
- app_models.migrations.0008_auto_20200422_1048 module
- app_models.migrations.0009_auto_20200427_0944 module
- app_models.migrations.0010_auto_20200428_1558 module
- app_models.migrations.0011_anonymouscomments module
- app_models.migrations.0012_auto_20200516_0059 module
- app_models.migrations.0013_userextratest module
- app_models.migrations.0014_feiuser module
- app_models.migrations.0015_auto_20200518_1059 module
- app_models.migrations.0016_auto_20200518_1424 module
- app_models.migrations.0017_auto_20200518_1437 module
- app_models.migrations.0018_auto_20200518_1445 module
- Module contents
Submodules¶
app_models.admin module¶
-
class
app_models.admin.AnonymousCommentsAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin-
fields= ['name', 'phone', 'email', 'comments', 'create_time']¶
-
list_display= ['name', 'phone', 'email', 'comments', 'create_time']¶
-
property
media¶
-
-
class
app_models.admin.CategoryAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin-
fields= ('category_type_name', 'category_type_code')¶
-
list_display= ('category_type_name', 'category_type_code')¶
-
property
media¶
-
-
class
app_models.admin.CustAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin除了注册的模型之外,增加一些字段,这些增加的字段来自于其它模型
- UserExtra:
‘weixin_openid’, ‘qq’
- UserAsset:
‘balance’
增加的这些字段,需要定义一个方法,和增加的字段名字一样的方法 例如字段名为 ‘weixin_openid’, 则 def weixin_openid(self, instance): 这个方法的参数是模型的实例,名字可以任取,但是传入的就是模型实例, 例如这里注册的是模型NewUserInfo,那么传入的实际就是NewUserInfo的一个实例,也就是一个user object
-
fields= ('username', 'first_name', 'last_name')¶
-
inlines= [<class 'app_models.admin.UserExtraInline'>, <class 'app_models.admin.UserAssetInline'>]¶
-
list_display= ('cust_field1', 'username', 'first_name', 'last_name', 'weixin_openid', 'qq', 'balance')¶
-
property
media¶
-
class
app_models.admin.OrderAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin-
fields= ('user', 'order_number', 'total_price')¶
-
list_display= ('user', 'order_number', 'total_price')¶
-
property
media¶
-
-
class
app_models.admin.OrderDetailAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin-
fields= ('subuserorder', 'product', 'quntity')¶
-
list_display= ('subuserorder', 'product', 'quntity')¶
-
property
media¶
-
-
class
app_models.admin.ProductAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin管理Product模型
-
fields= ('category', 'warehouse', 'product_name', 'product_description', 'product_price', 'product_stock', 'for_sale')¶
-
list_display= ('product_name', 'product_description', 'product_price', 'product_stock', 'category', 'warehouse', 'for_sale')¶
-
property
media¶
-
-
class
app_models.admin.SubOrderAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin-
fields= ('userorder', 'sub_userorder_number')¶
-
list_display= ('userorder', 'sub_userorder_number')¶
-
property
media¶
-
-
class
app_models.admin.UserAssetInline(parent_model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.StackedInlineUserAsset StackedInline
- 模型关系:
UserAsset和User也是One to One 同样每个User都会有一条(且仅有一条)UserAsset记录 作为StackedInline,管理User的时候也可管理UserAsset
-
has_add_permission(request, obj=None)[源代码]¶ Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.
-
has_delete_permission(request, obj=None)[源代码]¶ Return True if the given request has permission to change the given Django model instance, the default implementation doesn’t examine the obj parameter.
Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to delete the obj model instance. If obj is None, this should return True if the given request has permission to delete any object of the given type.
-
property
media¶
-
model¶
-
class
app_models.admin.UserExtraInline(parent_model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.StackedInlineUserExtra模型作为StackedInline
- 模型关系:
UserExtra和User是One to One 因此每个User有一条(且仅有一条)UserExtra记录 作为StackedInline,现在管理每个User的时候,也可一起管理UserExtra
-
has_add_permission(request, obj=None)[源代码]¶ Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.
-
has_delete_permission(request, obj=None)[源代码]¶ Return True if the given request has permission to change the given Django model instance, the default implementation doesn’t examine the obj parameter.
Can be overridden by the user in subclasses. In such case it should return True if the given request has permission to delete the obj model instance. If obj is None, this should return True if the given request has permission to delete any object of the given type.
-
property
media¶
-
model¶
-
class
app_models.admin.UserInfo(id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined)[源代码]¶ 基类:
django.contrib.auth.models.User-
exception
DoesNotExist¶ 基类:
django.contrib.auth.models.DoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.contrib.auth.models.MultipleObjectsReturned
-
exception
-
class
app_models.admin.UserLogAdmin(model, admin_site)[源代码]¶ 基类:
django.contrib.admin.options.ModelAdmin-
fields= ['x_forwarded_for', 'x_real_ip', 'remote_addr', 'userid', 'username', 'datetime', 'url', 'method', 'payload']¶
-
list_display= ['x_forwarded_for', 'x_real_ip', 'remote_addr', 'userid', 'username', 'datetime', 'url', 'method', 'payload']¶
-
property
media¶
-
app_models.apps module¶
app_models.models module¶
[项目的models] 所有models的定义都在同目录下其它的文件中定义 所有定义models的文件,命名都类似这样:models_for_some_app.py 所有app用到的models都从这里import from .models_for_some_app import MyModel
app_models.models_comments module¶
留言功能
-
class
app_models.models_comments.AnonymousComments(*args, **kwargs)[源代码]¶ 基类:
django.db.models.base.Model匿名留言
用户名,电话,email,都可以空白
-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
comments¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
create_time¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
email¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
get_next_by_create_time(*, field=<django.db.models.fields.DateTimeField: create_time>, is_next=True, **kwargs)¶
-
get_previous_by_create_time(*, field=<django.db.models.fields.DateTimeField: create_time>, is_next=False, **kwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
phone¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
app_models.models_customuser module¶
仅测试,暂不引入;当前用OneToOneField的UserExtra方式扩展用户信息
app_models.models_drf_token module¶
drf token
app_models.models_extra_user module¶
[使用one to one扩展User模型]
-
class
app_models.models_extra_user.UserExtra(*args, **kwargs)[源代码]¶ 基类:
django.db.models.base.Model- [扩展django的用户模型]
user 是一个OneToOneField
- 参数
{[type]} -- [description] (models) –
-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
pay_password¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
phone¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
qq¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
save(*args, **kwargs)[源代码]¶ Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
-
user¶ Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
-
user_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
weixin_openid¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
app_models.models_order module¶
用户订单 UserOrder: 用户下的订单
- SubUserOrder: 如果需要,用户订单可能会分成几个;
如果没有拆分,那么就当成一个子订单,即每个用户订单,包含至少一个子订单或多个子订单
- OrderDetail: 订单详情,包括子订单号,购买的产品,每个购买产品的数量
根据用户订购产品种类,每个用户订单对应至少一个或多个子订单 每个子订单对应至少一个或多个订单详情
-
class
app_models.models_order.OrderDetail(id, subuserorder, product, quntity)[源代码]¶ 基类:
django.db.models.base.Model-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
product¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
product_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
quntity¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
subuserorder¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
subuserorder_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
-
class
app_models.models_order.SubUserOrder(id, userorder, sub_userorder_number)[源代码]¶ 基类:
django.db.models.base.Model-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
orderdetail_set¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
sub_userorder_number¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
userorder¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
userorder_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
-
class
app_models.models_order.UserOrder(id, user, order_number, total_price)[源代码]¶ 基类:
django.db.models.base.Model-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
order_number¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
subuserorder_set¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
total_price¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
user¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
user_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
app_models.models_product module¶
产品相关的模型:产品类目和产品 Category: 类目 Product: 具体产品
-
class
app_models.models_product.Category(*args, **kwargs)[源代码]¶ 基类:
django.db.models.base.Model类目的模型 :用于配置可用的产品类目。
-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
category_type_code¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
category_type_name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
product_set¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
exception
-
class
app_models.models_product.Product(*args, **kwargs)[源代码]¶ 基类:
django.db.models.base.Model产品列表,包含了所有的产品
- 参数
{[type]} -- [description] (models) –
-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
category¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
category_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
for_sale¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
orderdetail_set¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
product_description¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
product_name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
product_price¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
product_stock¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
warehouse¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
warehouse_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
class
app_models.models_product.Supplier(*args, **kwargs)[源代码]¶ 基类:
django.db.models.base.Model供应商
- 参数
{[type]} -- [description] (models) –
-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
supplier_code¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
supplier_name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
supplier_type¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
class
app_models.models_product.Warehouse(*args, **kwargs)[源代码]¶ 基类:
django.db.models.base.Model仓库信息配置 :warehouse_type_name: 仓库名称 :warehouse_code: 仓库代码
-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
product_set¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
warehouse_address¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
warehouse_code¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
warehouse_name¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
app_models.models_user_asset module¶
用户资产表 继续使用OneToOneField,从User模型扩展
-
class
app_models.models_user_asset.UserAsset(id, user, balance, last_update)[源代码]¶ 基类:
django.db.models.base.Model-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
balance¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
get_next_by_last_update(*, field=<django.db.models.fields.DateTimeField: last_update>, is_next=True, **kwargs)¶
-
get_previous_by_last_update(*, field=<django.db.models.fields.DateTimeField: last_update>, is_next=False, **kwargs)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
last_update¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
user¶ Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
-
user_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
app_models.models_user_role module¶
用户角色模型 简单快速的实现一个基于角色的权限控制 /rbac 用户和用户角色,是一对多的关系 不过现实的系统里,绝大多数用户只会具有一个角色,例如已认证用户或未认证用户 少数用户可能具有多个角色 这样总体来说,角色表的记录并不会膨胀到特别大,和用户表的记录数接近,略多一点,性能可以接受 当一个用户从未认证客户,经过认证变成已认证客户,一般仅保留认证客户的角色,未认证角色将会删除,这一点由认证的逻辑保证 在每个视图需要权限控制的视图,用装饰器来实现: @require_userrole()
-
class
app_models.models_user_role.UserRole(id, user, role_code)[源代码]¶ 基类:
django.db.models.base.Model-
exception
DoesNotExist¶ 基类:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned¶ 基类:
django.core.exceptions.MultipleObjectsReturned
-
get_role_code_display(*, field=<django.db.models.fields.CharField: role_code>)¶
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <django.db.models.manager.Manager object>¶
-
role_code¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
user¶ Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
-
user_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
app_models.tests module¶
app_models.urls module¶
app_models.views module¶
Module contents¶
这是一个专为模型创建的app
- 说明如下:
所有的模型都放在这个app里 所有的模型都以models_开头,后面再加上具体内容或用途,例如: models_customuser.py, 为自定义用户而创建的模型 models_extra_user.py, 为用户模型增加一些extra的信息 然后在models.py文件里,import 需要的模型类