Django模型:字段名称冲突

时间:2017-08-20 09:24:59

标签: django

我在我的一个Django练习项目中遇到错误。

以下是我的应用和各自的型号:

项目名称:django03

app:home

主/ model.py

from __future__ import unicode_literals

from django.db import models
from django.conf import settings
# Create your models here.

User = settings.AUTH_USER_MODEL

HOME_TYPE = (
    ('1','1'),
    ('2','2'),
    ('3','3'),
)


class Home(models.Model):
    home_owner = models.ForeignKey(User,null=False, verbose_name='Owner')
    hometype= models.CharField(max_length=100, null=False, default=1, 
choices=HOME_TYPE, verbose_name='Home Type')
    licenseid= models.CharField(max_length=200, null=False, unique=True, 
verbose_name='License ID')
archive = models.BooleanField(default=False)

def __str__(self):
    return self.licenseid

app:家具家具/ model.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from django.db import models

# Create your models here.

User = settings.AUTH_USER_MODEL

FURNITURE_DATA_IMPORT_SOURCE= (
    ('0', '0'),
    ('1', '1'),
    ('2', '2'),
)

class Furniture(models.Model):
    furniture_owner = models.ForeignKey(User, verbose_name='User')
    furniture_imported_via = models.CharField(max_length=200, default="0", null=False, choices=FURNITURE_DATA_IMPORT_SOURCE, verbose_name='Source of import')
    furniture_title = models.CharField(max_length=100, null=False, verbose_name='Furniture title')
    furniture_description = models.TextField(max_length=250, verbose_name='Furniture description')
    archive = models.BooleanField(default=False)

    def __str__(self):
        return self.furniture_title

应用:映射映射/ model.py

from __future__ import unicode_literals

from django.db import models
from home.models import Home
from furniture.models import Furniture

class HomeFurnitureMapping(models.Model):
    home = models.OneToOneField(
        Home,
        on_delete=models.CASCADE,
        null=False,
        unique=True,
        verbose_name='Home'
    )
    furniture = models.OneToOneField(
        Furniture,
        on_delete=models.CASCADE,
        null=False,
        unique=True,
        verbose_name='Furniture'
    )

app:furnitureupdates furnitureupdates / model.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from mappings.models import HomeFurnitureMapping
# Create your models here.

class FurnitureUpdate(models.Model):
    mapping_id = models.OneToOneField(
        HomeFurnitureMapping,
        on_delete=models.CASCADE,
        null=False,
        unique=True,
        verbose_name='Mapping ID'
         )
    update_status = num_pages = models.IntegerField(null=False, default=1)
    update_date = models.DateField(auto_now_add=True, null=False, verbose_name='Update date')
    update_time = models.TimeField(auto_now_add=True, null=False, verbose_name='Update time')

    def __str__(self):
        return self.mapping_id

当我尝试迁移 FurnitureUpdate 模型时,出现以下错误:

ERRORS:
furnitureupdates.FurnitureUpdate.num_pages: (models.E006) The field 'num_pages' clashes with the field 'num_pages' from model 'furnitureupdates.furnitureupdate'.

我不了解num_pages字段的出现位置。请指导我,如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

您需要更新此内容;

update_status = models.IntegerField(null=False, default=1)

num_pages = models.IntegerField(null=False, default=1)

var myApp = angular.module('myApp',[]);

var jsonInfo = {"count":[{"name":"one",count:0} ,{"name":"two",count:0},{"name":"three",count:0} ,{"name":"four",count:0}]}

function MyCtrl($scope) {
  $scope.data =jsonInfo;

  $scope.count = function (inc) {
     jsonInfo.count.forEach((item) => {
        item.count = item.name === inc.name? inc.count + 1 : 0; 
     });
  };
}