2017-08-11 35 views
0

iam在model.py中編寫我的代碼,但是我得到了我的開發server.Any建議是welcome.I任何建議welcome.I以前suggections在堆棧中,但我不能得到任何解決我的代碼的答案。 錯誤:下面的代碼是我得到的錯誤。下面我得到一個SyntaxError在我的model.py可能是我的代碼的問題

Unhandled exception in thread started by <function wrapper at 0x7fe6d63e4938> 
    Traceback (most recent call last): 
     File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper 
     fn(*args, **kwargs) 
     File "/usr/lib64/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run 
     autoreload.raise_last_exception() 
     File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception 
     six.reraise(*_exception) 
     File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper 
     fn(*args, **kwargs) 
     File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup 
     apps.populate(settings.INSTALLED_APPS) 
     File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 108, in populate 
     app_config.import_models() 
     File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 202, in import_models 
     self.models_module = import_module(models_module_name) 
     File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module 
     __import__(name) 
     File "/home/harrugg2/projects/django/church/tithe/models.py", line 24 
     def print(self): 
       ^
    SyntaxError: invalid syntax 

是我model.py

代碼
# -*- coding: utf-8 -*- 
from __future__ import unicode_literals 
from django.utils import timezone 
from django.db import models 

# Create your models here. 
class tithe(models.models): 
    genarationNo = models(ForeignKey('generationNo.User')) 
    memberid = models.IntField() 
    membername = models.VacharField() 
    tithe = models.IntField() 
    combinedoffering = models.IntField(max_length=45) 
    campmeetingoffering = models.IntField(IntField=45) 
    churchbuilding = models.IntField(max_length=45) 
    conference = models.IntField(max_length=45) 
    localchurch = models.IntField(max_length=45) 
    funds = models.IntField(max_length=45) 
    total = models.IntField(max_length=45) 
    created_date = models.DateTimeField(
      default=timezone.now) 
    printed_date = models.DateTimeField(
      blank=True, null=True) 

    def print(self): 
     self.printed_date = timezone.now() 
     self.save() 

    def __str__(self): 
     return self.generationNo 

    class Meta: 
     unique_together = ["generationNo","IntField"] 
     ordering = ["printed_date","membername"] 
+1

請不要使用['print'](https://docs.python.org/2/library/functions.html#print)的標準功能,您應該更改爲其他名稱.. –

回答

3

print是語言的關鍵字。它是保留的,不能用作標識符。 See this

1

正如其他人所說,print不是一個功能的好名字,但你的代碼有其他奇怪的東西。 在unique_together您引用一個不存在的字段。

+0

@noobunatrixx您指的是這個字段'unique_together = [「generationNo」,「IntField」]' – harri

+0

實際上,既不存在,因爲字段名稱中有一個拼寫錯誤'genarationNo'。 –

+0

@harri是的。 「IntField」與模型上的任何字段都不匹配。查看'unique_together'上的django文檔。另外,網上有很多django教程,可以幫助你更好地理解這些東西。 – noobinatrixxx

相關問題