2015-01-05 20 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

它開始工作。感謝名單! –

相關問題