English 中文(简体)
Django 很多物体没有属性
原标题:Django ManyToMany str object has no attribute

我对Django先生使用拼写姓名,不拿与这个名字有关的“目标”。 我试图利用许多“Tomany”关系,但我可以这样说。 我发现的错误是:

AttributeError at <URL>
 str  object has no attribute  _default_manager 

在此,我的模式如下:

models/hood.py

class Hood(models.Model):
    name = models.CharField(unique=True)
    restaurants=models.ManyToManyField(Restaurant, through="restaurant_hood_map.RestaurantHoodMap")

    class Meta:
        db_table = "hoods"
        app_label="delivery"

models/restaurant.py

class Restaurant(models.model):
    name=models.ForeignKey(CompanyName)
    is_active=models.BooleanField(default=True)

    class Meta:
        db_table="restaurants"
        app_label="delivery"

models/restuarant_hood_map.py

<import restaurant and hood>
class RestaurantHoodMap(models.Model):
    restaurant = models.ForeignKey(Restaurant)
    hood = models.ForeignKey(Hood)

    class Meta:
        db_table="restaurant_hood_map"
        app_label="delivery"

现在,我知道问题是什么? 当我试图把有关餐馆从霍德带走时,我正在发现这一错误。 这是因为它对待“逮捕者”。 餐厅”作为展示价值。 然而,我认为,为了避免循环依赖,大家同意使用扼制值? 至少是我想到的:

https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

I also followed this example, which looked like exactly what I wanted:

我如何告诉Django,不要为与M2M相关的领域建立一个表格?

然而,当你获得霍德物品并做保时,这似乎就不可行。 餐馆......酒吧。

任何帮助都将是非洲妇女联盟。

<><>UPDATE: 我对模型稍作改动,以更准确地显示所发生的情况。

最佳回答

我直截了这个数字。 由此可见,当你确定“通过”多图曼吉特的参数时,它就是指不同模块中的一类。

因此,在我的上述例子中,必须把餐馆HoodMap的班子纳入“爱护”模块,必须加以修改,以便它没有以下列名称设置单元:

restaurants=models.ManyToManyField(Restaurant, through="RestaurantHoodMap")

现在,我不敢肯定,这在达詹戈是不是ug。 我认为,你可以参考一个具有强烈声望的不同类别,但如果该类别属于不同的模块,则似乎没有。

问题回答

暂无回答




相关问题
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 ...

热门标签