Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
ATLbeer, thanks for the awesome first Django/Web experience. I haven't done much web development and basically spent most of my time working on imaging libraries and various python projects. So this is a refreshing experience and exciting since I am getting right into the action rather then learning php or brushing up my ruby skills. So thanks!

Also, I am using Eclipse and PyDev(an eclipse extension for python development) and it works wonderfully with Django after you add the django site-package path. For anyone who is looking for an editor check it out pydev/eclipse is fairly advanced. I also tried dong some django work in wingIDE, but its pricey unless you go thru the free copy for open source developers process(the biggest hurdle is waiting for the snail mail).

Adbot
ADBOT LOVES YOU

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
I have a quick question regarding the subclassing of models. My code has a few models which share a decent amount of common attributes and I am wondering if making a superclass then subclassing it would work well. I heard some chatter last year about subclassing not working well with models is this still the case(maybe in 0.96)? Is inheritance broken for models?

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
Can anyone recommend any talks or presentations about Django? I have already watched Web Development for Perfectionists with Deadlines(Google Tech Talk) given by Jacob Kaplan-Moss, and Snakes and Rubies. I seem to get a lot, including motivation, out of things like that.

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
When subclassing a non-abstract model, I know I can get the subclass instance from the superclass instance but I need to know its name. How do I get around that? I am new to django and web apps, so I have a feeling I am doing this wrong, but here is a fictional example
code:
class Achievement(models.Model):
    Completed = models.BooleanField()
    [....]
class GotoNewYork(Achievement):
    [....]
class SwimWithSharks(Achievement):
    [....]

achievements = Achievement.objects.all()
some_achievement = achievements[0]
Now if I know some_achievement is has asuperclass instance of SwimWithSharks I can get the subclass using 'somecity.swimwithsharks', but is there anyway to get the subclass without knowing its name? I know I could keep a list and just see if the variable is in instances namespace, but I figured something like this would have already been implemented.

tehk fucked around with this message at 14:11 on Nov 19, 2009

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.

Yay posted:

As I recall, somthing like this was talked about when ORM model inheritance was first proposed and implemented. It was rejected. Something to do with CORBA (of which I know nothing), I think.

Only 'simple' solution I can think of is using mixins to store the class name, and its backed up by my finding example code here.
Ah thanks for that, the problem is way bigger than I expected. I will just keep a list of classes which subclass the model as a attribute of Achievement and use a simple method like this to find the correct one
code:
class Achievement(Model):
    [...]
    subclass_list = ["gotonewyork", "swimwithsharks"]

    def get_subclass(self):
        for subclass in self.subclass_list:
            if subclass in dir(self):
                return getattr(self, subclass)
        return None

Adbot
ADBOT LOVES YOU

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
I also do not see why the method is not working, but you can make it a property using the property built-in if you'd like. Still the first method should work.

code:
class Purchase(models.Model):
    ...
    price = property(lambda self: sum((ticket.tier.price for ticket in self.ticket_set)))

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply