2015-01-05 18 views
0

Beacon_info应用程式模式 如下所示的代码是一个havinng领域我想要在另一个应用中作为外键使用,如下所示。在我的项目,我有两个应用程序,beacon_info和报价,我需要使用存储为外键从我beacon_info应用提供

from django.db import models 
from django.utils.encoding import smart_unicode 
from django.utils import timezone 
from datetime import datetime 

    class store(models.Model): 
      store_name = models.CharField('Store Name',max_length=100) 
      store_id = models.CharField('Store_ID', max_length=20, unique=True) 
      store_email = models.EmailField('Email_ID', max_length=254) 
      address = models.CharField('Address', max_length=250) 
      country = models.CharField('Country', max_length=50) 
      state = models.CharField('State', max_length=50) 
      city = models.CharField('City',max_length=50) 
      pincode = models.CharField('Pincode', max_length=15) 
      contact_no = models.CharField('Contact', max_length=15) 
      createdat = models.DateTimeField(auto_now=True) 
      def __unicode__(self): 
       return smart_unicode(self.id) 

信息的应用程序的模型

from django.db import models 
from django.utils.encoding import smart_unicode 
from beacon_info.models import * 
from django.utils import timezone 
from datetime import datetime 
class offer(models.Model): 
    offer_code = models.CharField(max_length=50) 
    store_code = models.ForeignKey('beacon_info.models.store') 
    entry_exit_type = models.CharField(max_length=50, null=True) 
    offername = models.CharField(max_length=100, null=True) 
    description = models.TextField() 
    membership = models.CharField(max_length=5, default=1) 
    start_time = models.DateTimeField() 
    end_time = models.DateTimeField() 
    createdat =models.DateTimeField(auto_now_add=True) 
    def __unicode__(self): 
     return smart_unicode(self.offername) 
+0

你真的不问问题 – Ngenator

回答

0
models.ForeignKey('beacon_info.models.store') 

应该

models.ForeignKey('beacon_info.store') 

的约定是使用app_name.model_name,也没有必要在这models

https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.ForeignKey

要引用另一个应用程序定义的模型,你可以明确地指定 与完整的应用标签的模型。例如,如果 Manufacturer模型上面是另一个应用程序定义了一个名为 production,你需要使用:

class Car(models.Model): 
    manufacturer = models.ForeignKey('production.Manufacturer') 
+0

它开始工作。感谢名单! –

相关问题