错误:一个或多个模型未验证,向定义添加related_name参数

时间:2018-02-05 08:02:02

标签: python django python-2.7

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

错误:一个或多个模型未验证: ipn.paypalipn:与相关字段的字段“自定义”冲突的访问者 'Actor.paypalipn_set'。将related_name参数添加到定义中 “自定义”。 dashboard.paypalipn:与相关字段的字段“自定义”冲突的访问者 'Actor.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,Actor

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()

1 个答案:

答案 0 :(得分:0)

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

在这两个models.py中你有一个名为&#34; Paypalipn&#34;这两个模型的字段名为&#34; custom&#34;与相关的&#34;演员&#34;模型。

所以当Django尝试与#34; Actor&#34;进行反向关系时模型它们都是相同的&#34; Actor.paypalipn_set&#34;

所以你需要添加&#34; related_name&#34;两个模型(dasboard / paypalipn和ipn / paypalipn)中定义的参数对于&#39; custom&#39;字段