English 中文(简体)
Django 违约选择示范经理
原标题:Django Model Manager for Default Options

我有一个Django模式,具有可选择的外国钥匙。 我确定这种方式,以便表格能够包含不同的<代码>服务——类型的缺省选择,但可以通过指明<代码><> 控制器/代码>外国钥匙来推翻这一选择。

在我看来,我有一套这样的法典:

try:
    modeService = RegressionServices.objects.get(controller=controller, service_type=SERVICE_TYPE_CONTROLLER_MODE)
except RegressionServices.DoesNotExist:
    modeService = RegressionServices.objects.get(service_type=SERVICE_TYPE_CONTROLLER_MODE)

我想将这一条降为一个电话,我认为,Django模型Manager应当成为这样做的途径。 基本上,它将在<代码>**kwargs上对控制器进行检查,如果存在,则基本上将采用上述代码。 我正在研究该书,只是发现get_query_set方法通常被压倒。 凌驾于<代码>get()方法之上吗? 我甚至能否在模型管理员<代码>植被(<>方法>上查阅<代码>。

谁能想出一种办法,而不是模范管理人?

最佳回答

仅凭逻辑OR,使用Qbject

问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签