Reputation: 5017
I have the problem with creation of Referral from pinax-referrals package. Referral class has class function create(...) When I am trying to create referral inside view like:
from pinax.referrals.models import Referral
def createReferral(user):
referral = Referral.create(
user = user,
redirect_to = "/"
)
It throws me following error:
type object 'Referral' has no attribute 'create'
The code inside Pinax model looks ok:
@classmethod
def create(cls, redirect_to, user=None, label="", target=None):
if target:
obj, _ = cls.objects.get_or_create(
user=user,
redirect_to=redirect_to,
label=label,
target_content_type=ContentType.objects.get_for_model(target),
target_object_id=target.pk
)
else:
obj, _ = cls.objects.get_or_create(
user=user,
label=label,
redirect_to=redirect_to,
)
return obj
As I understand the problem is not connected to the Pinax package itself and looks really strange. Does anybody have any ideas?
Upvotes: 3
Views: 1288
Reputation: 308779
It sounds like you have defined another class Referral
inside the same module, that has replaced Pinax's Referral
model.
This could happen because you have defined a class,
class Referral(View):
...
or maybe you have imported another class Referral
. It might not be obvious this has happened if you do a *
import.
from mymodule import *
A useful tool to debug is to add print(Referral)
to you view. Then you will see whether the Referral
class is the one you expect.
Upvotes: 1