Re: Overriding methods in models of other developers

2019-07-27 Thread Jani Tiainen
You can do that with proxy models which allows you to override and add methods. Of course if there is a need to really modify original model it gets tricky. la 27. heinäk. 2019 klo 10.49 אורי kirjoitti: > Hi, > > I had to change the following lines because tests failed: > > class

Re: Overriding methods in models of other developers

2019-07-27 Thread אורי
Hi, I had to change the following lines because tests failed: class Friend1(object): def __str__(self): return "User {} is friends with {}".format(self.to_user, self.from_user) class FriendshipRequest1(object): def __str__(self): return "Friendship request from user {}

Overriding methods in models of other developers

2019-07-27 Thread אורי
Django users, I want to override def __str__ of models I'm using, but the models are maintained by other developers. I think the __str__ is only used by the admin interface. I found out that I can do something like this: from django.contrib import admin from django.contrib.sites.models import

Re: Methods in Models

2016-10-26 Thread Deep Shah
This makes sense! Thanks! On Monday, October 24, 2016 at 1:17:26 PM UTC+5:30, Deep Shah wrote: > > What kind of methods should be part of the models and what should be in > the views? Can anyone give me an example of a method which should be in a > Model than the views file? > -- You received

Re: Methods in Models

2016-10-24 Thread Asad Jibran Ahmed
Any method that works *only* with the model data and is used in multiple places in the application should be a part of the model. Next, if you have functions that operate on multiple pieces of data (or more than 1 model instances) you should put them in the view where they are used. But if these

Methods in Models

2016-10-24 Thread Deep Shah
What kind of methods should be part of the models and what should be in the views? Can anyone give me an example of a method which should be in a Model than the views file? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from

Re: Returning values from calculations done by custom methods in models

2012-02-18 Thread Gchorn
Whoops, wow that really was basic Python. Sorry for the spam; of course I know there's a difference between calling a method and calling an attribute...how embarassing. =) Thanks for your help Anssi. Also thanks for not adding, ", you moron!" to the end of each sentence... On Feb 19, 9:47 am,

Re: Returning values from calculations done by custom methods in models

2012-02-18 Thread akaariai
On Feb 19, 3:38 am, Gchorn wrote: > Hello All, > > So in my models.py file, I have: > > class Player(models.Model): >         team = models.ForeignKey(Team) >         first_name = models.CharField(max_length=100) >         last_name = models.CharField(max_length=100) >  

Returning values from calculations done by custom methods in models

2012-02-18 Thread Gchorn
Hello All, So in my models.py file, I have: class Player(models.Model): team = models.ForeignKey(Team) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) gp = models.IntegerField(max_length=2) #games played mp =