There are views.py :

def view(request): ... InfoMessage.createinfo('self',request.user, 3) ... 

And model

 class InfoMessage(models.Model): to_view=models.BooleanField(default=True) choice=models.CharField(max_length=1, choices=INFO_MESSAGE_CHOICES) user=models.ForeignKey(CustomUser) def createinfo(self, user, choice): obj=super(InfoMessage, self).objects.create(user=user, choice=choice) obj.save() 

As a result, I get

unbound method create info () must be called with InfoMessage instance as first argument (got str instance instead)

How to fix it?

  • Yes, I did one line in a view - LiGhT_WoLF 7:44 pm


1 answer 1

Remove 'self' .

  • In which place? And then there are a lot of them. - LiGhT_WoLF
  • in the view where you call InfoMessage.createinfo ('self', request.user, 3) - breaf
  • tried without it, does not help - LiGhT_WoLF
  • one
    Well, it turns out, there is no instance yet, you must first create and then call the method using self. In general, everything looks a bit strange. What is the purpose? Just to record, why then this method? why not to do: msg = InfoMessage.objects.create (choice = '3', user = request.user) msg.save ()? - breaf
  • one
    I'm sorry, I'm a little confused myself, if you use objects.create (), then you do not need to call .save (). Those. this is exactly what you wanted, in one line to make an entry in the database, I understand correctly? - breaf 7:42 pm