【问题标题】:Error: One or more models did not validate, Add a related_name argument to the definition错误:一个或多个模型未验证,在定义中添加 related_name 参数
【发布时间】:2018-02-05 08:02:02
【问题描述】:

在我的应用程序中运行“manage.py validate”时出现此错误。

错误:一个或多个模型未验证: ipn.paypalipn:字段“自定义”的访问器与相关字段冲突 '演员.paypalipn_set'。在定义中添加一个 related_name 参数 '风俗'。 dashboard.paypalipn:字段“自定义”的访问器与相关字段冲突 '演员.paypalipn_set'。在定义中添加一个 related_name 参数 '自定义'。

这是我在 Dashboard/models.py 下获得的另一个 model.py

@csrf_exempt
def show_me_the_money(sender, **kwargs):

ipn_obj = sender

actor_id = ipn_obj.custom

if actor_id == "Upgrade all users!":
    User.objects.update(paid=True)

if ipn_obj.payment_status == "Completed":

    from actors.models import Actor
    from commerce.models import Transaction

    actor = Actor.objects.get(id=actor_id)

    accountdetails = actor.account_set.latest('pk')

    signupbonus = 0


    transaction = Transaction()
    transaction.actor = actor
    transaction.amount = ipn_obj.mc_gross
    transaction.currency = ipn_obj.mc_currency
    transaction.transaction_flag = 'paid'
    transaction.transaction_type = 'deposit'
    transaction.payment_method = 'Paypal'
    transaction.payment_reference = ipn_obj.txn_id
    transaction.payment_message = 'OK'
    transaction.transaction_date = timezone.now()
    transaction.UserIp = actor_ip()
    transaction.save()           

    currentamount = accountdetails.balance
    accountdetails.balance = float(signupbonus) + float(currentamount) + float(ipn_obj.mc_gross)
    accountdetails.save()

payment_was_successful.connect(show_me_the_money)

在models.py中,演员

class Actor(User):

def create_actor_number():
    try:
        return int(Actor.objects.order_by('-id')[0].actor_key) + 1
    except:
        return 5001

ssn = models.CharField(max_length=32, default='', blank=True, help_text="Social security number")
address = models.OneToOneField(ActorAddress, null=True, blank=True, help_text="Actor full address information")
phone_number = models.CharField(max_length=32, default='', blank=True, help_text="Actor main phone number (Format: + and country-code eg +4670323435)")
alt_phone_number = models.CharField(max_length=32, default='', blank=True, help_text="Actor alternative phone number")
alt_email = models.EmailField(default='', blank=True, help_text="Actor alternative email")
skype = models.CharField(max_length=128, default='', blank=True, help_text="Actor Skype ID")
twitter = models.CharField(max_length=128, default='', blank=True, help_text="Actor Twitter account")
website = models.URLField(max_length=200, default='', blank=True, help_text="Actor Website URL")
blog = models.URLField(max_length=200, default='', blank=True, help_text="Actor Blog URL")   
linkedin_name = models.CharField(max_length=128, default='', blank=True, help_text="Actor LinkedIn account name") 
linkedin_ref = models.CharField(max_length=128, default='', blank=True, help_text="Actor LinkedIn reference number")
description = models.TextField(blank=True, help_text="More information about Actor")
company = models.ForeignKey(ActorCompany, null=True, blank=True)  
language = models.CharField(max_length=8, choices=LANGUAGES, default='', blank=True, help_text="Stored as ISO codes (Sv, En, etc) in the DB")
timezone = models.CharField(max_length=10, default='UTC+01:00', blank=True, help_text="UTC TimeZone <a href='http://en.wikipedia.org/wiki/Time_zone' target='_blank'>(http://en.wikipedia.org/wiki/Time_zone)</a>, eg UTC+01:00 for London")
invite_code = models.CharField(max_length=16, default='', blank=True, help_text="invite code")
updated_on = models.DateTimeField(auto_now=True, auto_now_add=True, help_text="Auto generated by system")
lockout_times = models.CharField(max_length=10, default='', blank=True, help_text="lockout times")
actor_key = models.CharField(max_length=128, default=create_actor_number, help_text="Actor unique key key used for identification")
secret_key = models.CharField(max_length=128, default=make_uuid, help_text="Actor unique secret key used to identify the Actor in API calls")
access_key = models.CharField(max_length=128, default=make_uuid, help_text="Actor unique access key used to identify the Actor in API calls")
confirmation_key = models.CharField(max_length=128, default=make_uuid, help_text="Registered user validate email")
email_confirmation = models.BooleanField(default=False, help_text="To Check if User validated email")
type = models.CharField(max_length=128, default='', blank=True, help_text="NOT IN USE")
category = models.CharField(max_length=128, default='', blank=True, help_text="NOT IN USE")
partner_status = models.BooleanField(default=False, blank=False, help_text="Describe whether the actor is partner of. If Actor is partner, True will be stored. False is the default value.")
partner_commission = models.FloatField(default=0.0, help_text="Commission percentage allocated to partner")  
partner = models.ForeignKey('actors.Actor', related_name='partner_from', limit_choices_to={"partner_status": "true"}, null=True, blank=True, help_text="This actor is connected to partner.")
#To Check if User Logged in for the first time
is_first = models.BooleanField(default=True, help_text="To Check if user logged in for the first time.")
signup_method = models.CharField(max_length=128, default='', blank=True, help_text="Determine how the user is registered in")
pkb_email = models.BooleanField(default=True, verbose_name='Send partner kickback email', help_text="To check e-mail should be sent to partner")
email_subscribed = models.BooleanField(default=True, help_text="Subscribe to notice e-mail")
sales_email = models.BooleanField(default=True, help_text="To check e-mail should be sent to seller")
is_sellerregistered = models.BooleanField(default=False, help_text="To check if user registered for seller account.")
Login_IPnumber = models.CharField(max_length=100, default='', blank=True, help_text="stores user ip when log in.")
Registration_IPnumber = models.CharField(max_length=100, default='', blank=True, help_text="stores user ip when registration.")
google_client_id = models.CharField(max_length=50, default='', blank=True, help_text="Google client ID.")
seller_commission = models.FloatField(default=-1.0, help_text="Seller commission percentage. Standard 50, 40, 30 or -1 for 0 commission")
currency = models.CharField(max_length=6, default=settings.BASE_CURRENCY, help_text="Actor's currency in ISO format")
objects = ActorManager()

【问题讨论】:

  • 发布你的 models.py 文件
  • 我已经编辑了我的问题,你可以看到

标签: python django python-2.7


【解决方案1】:

我认为您的项目有两个 models.py 文件,其中一个在仪表板目录下,另一个在 ipn 目录下。

在这两个models.py中,你有一个名为“Paypalipn”的模型,这两个模型有一个名为“custom”的字段和相关的“Actor”模型。

所以当 Django 尝试从“Actor”模型建立反向关系时,它们都是相同的“Actor.paypalipn_set”

因此,您需要在两个模型(dasboard/paypalipn 和 ipn/paypalipn)中为“自定义”字段的定义添加“related_name”参数

【讨论】:

  • 啊,好吧,我现在看到我拥有多个具有相同名称的类。我刚刚删除了一个我没有使用的。谢谢帮助
猜你喜欢
  • 2014-03-07
  • 2013-02-13
  • 1970-01-01
  • 2011-02-06
  • 2013-04-06
  • 1970-01-01
  • 2015-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多