Tuesday, February 26, 2013

Re: How to abstract model methods to a separate class?

On Tue, 2013-02-26 at 07:53 -0800, Richard Brockie wrote:
> class myLinksClass:
> basepath = 'testing/'
>
> def self(self):
> return "%s" % (self.basepath, )
>
> def view1(self):
> return "%s%s" % (self.basepath, 'view1', )
>
> def view2(self):
> return "%s%s" % (self.basepath, 'view2', )
>
> class MyModel(models.Model):
>
> date = models.DateField()
> slug = models.SlugField()
>
> def links(self):
> thelinks = myLinksClass
> return thelinks

If this is the actual syntax you used, then my best guess is that the
problem is that you are passing a class rather than an instanciated
object and those aren't class methods. Either instanciate an object or
remove the "self" arguments to make those class methods and it should
work.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment