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
nbv4
Aug 21, 2002

by Duchess Gummybuns
Is django-tagging still the best tagging extension? A google search brings up a lot of blogs that would assume it still is, but the latest official version doesn't even support 1.0.

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

nbv4 posted:

Is django-tagging still the best tagging extension? A google search brings up a lot of blogs that would assume it still is, but the latest official version doesn't even support 1.0.

Works pretty well for me, and it has a nice tag cloud template tag that it comes with that works well for my needs :)

nbv4
Aug 21, 2002

by Duchess Gummybuns

No Safe Word posted:

Works pretty well for me, and it has a nice tag cloud template tag that it comes with that works well for my needs :)

Yeah I used it on an abandoned project that I'm going back to. I don't know whether I should dump it and use my own code, or use it and run the risk of having to dump it later on when it no longer works in django due to it being abandoned.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Ok guys I'm having a heard time wrapping my head around the model formsets. Here is my model:
code:
class Absence (models.Model):
    group = models.ForeignKey(Grupo)
    student = models.ForeignKey(Alumno)
    date = models.DateTimeField()
    absent = models.BooleanField(default=False)
I want to create a modelformset with some initial data for the group, student, and date fields and presents the teacher with a list of students and a checkbox next to each of their names but it gives me an error with just a simple dictionary.
"IndexError (list index out of range)"

code:
AbsenceFormSet = modelformset_factory(Absence)
formset = AbsenceFormSet(initial=[{'date': datetime.now()}])
What am I doing wrong?

nbv4
Aug 21, 2002

by Duchess Gummybuns


The screen shot is from the "edit" page of this model:

code:
class Position(models.Model):
	company		=	models.ForeignKey("Company")
	
	name		=	models.CharField(max_length=32, blank=True)
	job_domain	=	models.IntegerField(choices=JOB_DOMAIN, default=0)

[...]
	
	bases		=	models.ManyToManyField(Base, through="PosBase", blank=True, null=True)
and here is the model that is being inlined:

code:
class PosBase(models.Model):
	position	=	models.ForeignKey(Position)
	base		=	models.ForeignKey(Base)
	base_entry	=	models.IntegerField(choices=BASE_ENTRY, default=0)
	hiring_status	=	models.IntegerField(choices=HIRING_STATUS, default=0)
	hiring_status_date=	models.DateField(blank=True, null=True)
[...]
and here is the inlining code:

code:
class PosBaseInline(admin.TabularInline):
	model = PosBase
	extra = 3
	
class PositionAdmin(admin.ModelAdmin):	
	inlines = (PosBaseInline,)

admin.site.register(Position, PositionAdmin)
My problem is that everytime I want to edit a Position object, it complains if I leave the three inline PosBase objects empty. I have two other inlines on other models that are just ignored when you try to save the object with blank inlines. I can't figure out why it's doing this. I tried changing around "blank=True, null=True" in the ForeignKey fields, but all that seems to do it cause a totally blank object to be saved and then linked to the parent object. What the heck...

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

nbv4 posted:

My problem is that everytime I want to edit a Position object, it complains if I leave the three inline PosBase objects empty. I have two other inlines on other models that are just ignored when you try to save the object with blank inlines. I can't figure out why it's doing this. I tried changing around "blank=True, null=True" in the ForeignKey fields, but all that seems to do it cause a totally blank object to be saved and then linked to the parent object. What the heck...

Try getting rid of the default=0.

nbv4
Aug 21, 2002

by Duchess Gummybuns

deimos posted:

Try getting rid of the default=0.

hoooooly balls that worked. I had no idea defautl=0 was causing that. Thanks.

No Safe Word
Feb 26, 2005

nbv4 posted:

hoooooly balls that worked. I had no idea defautl=0 was causing that. Thanks.

Well, I bet if you went to the trouble of changing "unknown" and "not hiring" to the "------" entries on each of those drop-downs it would work too. It sees a partially completed entry and assumes you intended to complete it so it's letting you know which fields in those partially completed entries need to be filled in to complete them.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

nbv4 posted:

Is django-tagging still the best tagging extension? A google search brings up a lot of blogs that would assume it still is, but the latest official version doesn't even support 1.0.

Here's a nice jquery addition that'll give you an auto-complete dropdown for tag fields: http://jannisleidel.com/2008/11/autocomplete-widget-for-django-tagging-form-fields/

I took this and modified it a bit to be an inclusion templatetag so that I could apply it to front-end tag fields easily.

Ferg
May 6, 2007

Lipstick Apathy
Anal retentive question: what editors support the syntax highlighting for an HTML view with the {% %} tags? I'm using PyDev currently, though I only defaulted to that because I use Eclipse so much at work. I'm open to other editors if Eclipse can't handle that syntax.

Forzan
Mar 15, 2002

by Ozmaugh

Ansible posted:

It's a webapp and I freakin love it. Here is a hosted version but it's also very small and you can throw it on your own space pretty easily:

http://ondras.zarovi.cz/sql/demo/

Thanks for the responses, I was hoping for a built in template function but I think that I see the way to do this via views - if not, i'll build out some templating

Thank you so much for sharing this. This is the most useful, free database designer I have ever used.

No Safe Word
Feb 26, 2005

Ferg posted:

Anal retentive question: what editors support the syntax highlighting for an HTML view with the {% %} tags? I'm using PyDev currently, though I only defaulted to that because I use Eclipse so much at work. I'm open to other editors if Eclipse can't handle that syntax.

vim supports the django template syntax

nbv4
Aug 21, 2002

by Duchess Gummybuns
How do you get access to objects linked from ForeignKey and ManyToMany fields within the parent object?

here is my model:

code:
class Route(models.Model):
	points		=	models.ManyToManyField("Point", through="RoutePoint")
	often		=	models.IntegerField(choices=ROUTE_OFTEN, default=0)
	
	def center(self):
		all_lats = []
		all_longs = []
		
		for point in self.points.all()
			all_lats.append(point.lat)
			all_longs.append(point.long)

                #[some code goes here]
		
		return u"center_lat=%s; center_long=%s" % (center_lat, center_long)
I'm writing a function that takes all the points in a route and determines the center longitude/lattitude location of all the points. I somehow need to get access to all the points that are related to the route object, but I can't figure out how. I tried doing "Route.objects.get(pk=self.pk)" (like you would in a view) but that doesn't work either. Am I going about this problem the Wrong™ Way™® (all right reserved)?

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

nbv4 posted:

How do you get access to objects linked from ForeignKey and ManyToMany fields within the parent object?

here is my model:

code:
class Route(models.Model):
	points		=	models.ManyToManyField("Point", through="RoutePoint")
	often		=	models.IntegerField(choices=ROUTE_OFTEN, default=0)
	
	def center(self):
		all_lats = []
		all_longs = []
		
		for point in self.points.all()
			all_lats.append(point.lat)
			all_longs.append(point.long)

                #[some code goes here]
		
		return u"center_lat=%s; center_long=%s" % (center_lat, center_long)
I'm writing a function that takes all the points in a route and determines the center longitude/lattitude location of all the points. I somehow need to get access to all the points that are related to the route object, but I can't figure out how. I tried doing "Route.objects.get(pk=self.pk)" (like you would in a view) but that doesn't work either. Am I going about this problem the Wrong™ Way™® (all right reserved)?

Not sure if you've asked the right question since the correct answer is right in your snippet: self.points.all()

nbv4
Aug 21, 2002

by Duchess Gummybuns

jupo posted:

Not sure if you've asked the right question since the correct answer is right in your snippet: self.points.all()

Yeah I just got it working. It was something else causing the error. Now I'm having another similar problem:

code:
class PosBase(models.Model):
	position	=	models.ForeignKey("Position")
	base		=	models.ForeignKey("Base")
	
	#[more stuff]
	
	def __unicode__(self):	
		return u"%s - %s" (self.base.identifier, self.position.name)
the unicode function isn't working. How do I get those values? I understand why the example in my last post worked since a manager is being called. But for this one? I don't see how I can get those two objects populated... The error I'm getting is "Caught an exception while rendering: 'unicode' object is not callable"

bitprophet
Jul 22, 2004
Taco Defender

nbv4 posted:

Yeah I just got it working. It was something else causing the error. Now I'm having another similar problem:

code:
class PosBase(models.Model):
	position	=	models.ForeignKey("Position")
	base		=	models.ForeignKey("Base")
	
	#[more stuff]
	
	def __unicode__(self):	
		return u"%s - %s" (self.base.identifier, self.position.name)
the unicode function isn't working. How do I get those values? I understand why the example in my last post worked since a manager is being called. But for this one? I don't see how I can get those two objects populated... The error I'm getting is "Caught an exception while rendering: 'unicode' object is not callable"

Missing a % operator between your Unicode string and what you intended to be the values interpolated into it. Thus it thinks the tuple of variables is actually you doing "mystring"(lol) which is syntax for trying to call a callable object.

Ferg
May 6, 2007

Lipstick Apathy

No Safe Word posted:

vim supports the django template syntax

Is there any particular vimrc options that need to be set for this? Anything between {% %} tags is just standard text color, including the tags themselves.

Edit: Nevermind, found this; http://www.vim.org/scripts/script.php?script_id=1487

Ferg fucked around with this message at 18:08 on May 11, 2009

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
For any newbies out there with some python knowledge the Django 1.0 Template Development book is absolutely amazing. Don't just browse it, READ IT. It's very in depth but easy to follow if you read the whole thing.

Ohh, and it's not just about Templates, it covers pretty much everything django.


edit: forgot to mention: it's not quite as easy on the newbie as bitpropbhet's, nor as broad on subjects. But it covers some nuances that are very important to a django developer, I have learned a LOT from it.

bitprophet posted:

Did you mean me? :shobon: I think bitkeeper is the "savagely optimized" guy.

eek, yeah I did, pretty sure I confused your name with the software product, didn't really feel like looking it up, sorry.

deimos fucked around with this message at 21:02 on May 28, 2009

bitprophet
Jul 22, 2004
Taco Defender

deimos posted:

edit: forgot to mention: it's not quite as easy on the newbie as bitkeeper's, nor as broad on subjects.

Did you mean me? :shobon: I think bitkeeper is the "savagely optimized" guy.

duck monster
Dec 15, 2004

Ansible posted:

Still a bit stuck on this but think I'm on the right track using model manager:

Whenever I reference a "Food" object, either through the Consumption model or directly, I want to have a few defined queries that will do some simple arithmetic and return a nutrient value. Nutrients are in value per 100g of Food, and modified by the measure and consumption amount.

So for example, when I loop through Consumption items, I want a Calorie query that will select a specific Nutrient item based on dynamic Food id and a static Nutr_Def id, then take (nutrient.value/100) * measure.grams * consumption.amount.

Is a model manager the correct way to do this, and if so should it be extending the Food model or should I put it in the consumption or measure models?

What are you doing your UML in?


edit: Oh yeah, I found a python script once that transformed dia UML into django models. Bit clunky, but it worked!

Ansible
Sep 11, 2003

This is what I get for trusting other people to give me stuff. And that's why I'm so lucky.

duck monster posted:

What are you doing your UML in?

This?: http://ondras.zarovi.cz/sql/demo/.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

bitprophet posted:

Did you mean me? :shobon: I think bitkeeper is the "savagely optimized" guy.

Have you read Scott's book? I made work buy your django book and read through it but haven't had time to really read it through except for some of the more advanced parts, and Marty's book which is equally awesome and metaclassy as gently caress.

bitprophet
Jul 22, 2004
Taco Defender

deimos posted:

Have you read Scott's book? I made work buy your django book and read through it but haven't had time to really read it through except for some of the more advanced parts, and Marty's book which is equally awesome and metaclassy as gently caress.

Sadly I haven't had the chance to read either of them :( in no small part because I just haven't been doing much Django lately, instead doing sysadmin stuff and Rails at work, and Fabric outside of work.

I sorta-know Marty and I'm sure his book is awesome, don't know Scott at all but it sounds like I should see if it's in my Safari subscription :)

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I currently have Client, Printer, Cartridge, and Order models.

The Printer model has a ManyToManyField to the Cartridge model, which would allow you to select all the cartridges that can be used with that printer.

The Cliente has a ManyToManyField to the printers which they own.

I want to create an Order through the Django Admin which lets your specify the Client, a dicount, and multiple cartridges through a ManyToManyField. This is getting kinda tricky because I have to do it through another table that specifies whether it's a new Cartridge or a refill. I want the admin to filters the Cartridges to only show the ones that belong to the printers that they own. Also I would like to have a field that holds the total price of their order, but it should calculate it based on how many cartridges they have added to the order.

I don't know if this should be done by adding more of the same cartridge to the order or by having another field in the through table that specifies the quantity.

Can this be done in the admin or do I need to use a form? And if so how would I go about adding this to the admin? It seems difficult and probably something I will have to do in multiple parts since in order to filter the list of cartridges I have to know the client beforehand.

Janitor Prime fucked around with this message at 16:37 on May 29, 2009

cowboy beepboop
Feb 24, 2001

Anyone have any experience/recommendations for django forums?

ATLbeer
Sep 26, 2004
Über nerd

my stepdads beer posted:

Anyone have any experience/recommendations for django forums?

There's a slightly out of date wiki on Django projects

http://code.djangoproject.com/wiki/ForumAppsComparison

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

my stepdads beer posted:

Anyone have any experience/recommendations for django forums?

I've used http://pybb.org/ on a couple of projects and it's great. It's essentially a clone of phpbb as a Django app.

cowboy beepboop
Feb 24, 2001

Cheers guys. I'd been leaning towards pybb.

MonkeyMaker
May 22, 2006

What's your poison, sir?
So, here's the code, first:
code:
class Period(models.Model):
    """ When the bells ring for a class period """
    start_time = models.TimeField()
    end_time = models.TimeField()

class BellSchedule(models.Model):
    """ Ordered bells for a given school """
    school = models.ForeignKey('School')
    first = models.ForeignKey('Period', related_name="1st Period")
    second = models.ForeignKey('Period', related_name="2nd Period")
    third = models.ForeignKey('Period', related_name="3rd Period")
    fourth = models.ForeignKey('Period', related_name="4th Period")
    fifth = models.ForeignKey('Period', related_name="5th Period")
    sixth = models.ForeignKey('Period', related_name="6th Period")
    seventh = models.ForeignKey('Period', related_name="7th Period")
    eight = models.ForeignKey('Period', related_name="8th Period",
        null=True, blank=True)
    ninth = models.ForeignKey('Period', related_name="9th Period",
        null=True, blank=True)
    tenth = models.ForeignKey('Period', related_name="10th Period",
        null=True, blank=True)
Now, this works fine if I want to do bellschedule.first.start_time, bellschedule.first.end_time, etc. I don't want to do that most of the time. I'd rather be able to do "for period in bellschedule.periods" and just iterate through them.

So, how do I do this? I've gotten myself into this mess but can't seem to get myself out of it.

Thanks.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
code:
class BellSchedule(models.Model):
    [...]
    @property
    def periods(self):
        names = "first second third fourth fifth sixth seventh eight ninth tenth".split()
        return [getattr(self, name) for name in names]

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
django now runs on Glassfish V3. Huzzah. Now there's no platform left to escape the power of django.

MonkeyMaker
May 22, 2006

What's your poison, sir?
Thanks a ton, Janin. That works great.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

MonkeyMaker posted:

Now, this works fine if I want to do bellschedule.first.start_time, bellschedule.first.end_time, etc. I don't want to do that most of the time. I'd rather be able to do "for period in bellschedule.periods" and just iterate through them.

So, how do I do this? I've gotten myself into this mess but can't seem to get myself out of it.

Thanks.

How about :

code:
class Period(models.Model):
    """ When the bells ring for a class period """
    period = models.IntegerField(choices=enumerate(range(1, 10)))
    start_time = models.TimeField()
    end_time = models.TimeField()
    schedule = models.ForeignKey('BellSchedule', related_name="periods")
    class Meta:
        ordering = ["period"]

class BellSchedule(models.Model):
    """ Ordered bells for a given school """
    school = models.ForeignKey('School')
This makes proper use of the "related_name" argument which I believe you've misunderstood in your first example and cleans up your repetition a lot.

You can then use the "extra" and "max_num" arguments for your inline formsets wherever the data is managed, either the admin or your own formsets.

MonkeyMaker
May 22, 2006

What's your poison, sir?
Thanks, jupo, I'll give that a try too.

On these same models, I need to associate a set of classes and their teacher to a given bell schedule and I'm pretty lost on trying to figure it out. Any ideas/help?

duck monster
Dec 15, 2004

deimos posted:

django now runs on Glassfish V3. Huzzah. Now there's no platform left to escape the power of django.

I've always wanted to enhance my Django experience with the joys of configuring a mindfuckingly huge number of complicated XML files.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

duck monster posted:

I've always wanted to enhance my Django experience with the joys of configuring a mindfuckingly huge number of complicated XML files.

Actually, I haven't had to touch an XML file on our glassfish servers since... ohh... never. It has a very sexy web-based administrator. Also, setting up a dynamic language site is stupid easy, all you have to do is declare a new container and tell it it's gonna be python/ruby/whatever and configure a couple more variables and huzzah, django. It's actually easier than configuring apache.

caveat; I haven't done anything more than get it up and running, haven't actually transfered a decently sized django to glassfish and tested. Also, our glassfish cluster has a person that maintains it.

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

MonkeyMaker posted:

Thanks, jupo, I'll give that a try too.

On these same models, I need to associate a set of classes and their teacher to a given bell schedule and I'm pretty lost on trying to figure it out. Any ideas/help?

It's hard to say without a full picture of what you're trying to achieve. It looks like you've got a basic understanding of managing related data via models. Based on the little info you've given and extending off the previous example:

code:
class Teacher(models.Model):
    name = models.CharField(max_length=50)

class Class(models.Model):
    name = models.CharField(max_length=50)
    teacher = models.ForeignKey("Teacher", related_named="classes")
    schedule = models.ForeignKey("BellSchedule", related_named="classes")
How does that look to you?

MonkeyMaker
May 22, 2006

What's your poison, sir?

jupo posted:

It's hard to say without a full picture of what you're trying to achieve. It looks like you've got a basic understanding of managing related data via models. Based on the little info you've given and extending off the previous example:

code:
class Teacher(models.Model):
    name = models.CharField(max_length=50)

class Class(models.Model):
    name = models.CharField(max_length=50)
    teacher = models.ForeignKey("Teacher", related_named="classes")
    schedule = models.ForeignKey("BellSchedule", related_named="classes")
How does that look to you?

Thanks for the help but it's definitely more complex than that, I think. OK, let me try to break this down:

Schools have multiple teachers and may have multiple bell schedules (different day types [a, b, block, etc])
Teachers have multiple classes, obviously, and can have multiple class schedules (see the above bell schedules for the idea)
Obviously teachers at the same school share bell schedules and their periods and may share classes, but I don't care TOO much about optimizing that right now.

Here's my start and it seems to be working in the shell:
code:
class School(models.Model):
    """
    Each school has multiple teachers and multiple bell schedules
    """
    
    school_name = models.CharField(max_length=255)
    school_type = models.CharField(max_length=255)
    zip_code = models.IntegerField(db_index=True)
    
    def __unicode__(self):
        return self.school_name

class Teacher(models.Model):
    """
    Teachers belong to a single school and are primarily identified by their
    email address. Teachers can have multiple class schedules
    """
    
    TITLE_CHOICES = (
        ('Mr.', 'Mr.'),
        ('Mrs.', 'Mrs.'),
        ('Ms.', 'Ms.'),
        ('Miss', 'Miss'),
        ('Dr.', 'Dr.')
    )
    title = models.CharField(max_length=4, choices=TITLE_CHOICES)
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    email = models.EmailField(unique=True, db_index=True)
    school = models.ForeignKey('School')
    
    def __unicode__(self):
        return self.title +" "+ self.first_name +" "+ self.last_name

class Period(models.Model):
    """
    When the bells ring for a class period
    """
    
    period = models.IntegerField(choices=enumerate(range(1, 8)))
    start_time = models.TimeField()
    end_time = models.TimeField()
    schedule = models.ForeignKey('BellSchedule', related_name="periods")
    
    class Meta:
        ordering = ["period"]

class BellSchedule(models.Model):
    """
    Ordered bells for a given school
    """
    
    school = models.ForeignKey('School')

class Day(models.Model):
    """
    Day for a given teacher.
    """
    
    DAY_CHOICES = (
        ('A', 'A-Day'),
        ('B', 'B-Day'),
        ('C', 'C-Day'),
        ('Admin', 'Administrative'),
        ('Normal', 'Normal')
    )
    teacher = models.ForeignKey('Teacher')
    bellschedule = models.ForeignKey('BellSchedule')
    day_type = models.CharField(max_length=255, choices=DAY_CHOICES)

class ClassSchedule(models.Model):
    """
    Classes for a given day for a given teacher.
    Trying to build off of the Period idea.
    """
    
    LEVEL_CHOICES = (
        ('Average', 'Average'),
        ('ESL', 'ESL')
    )
    period = models.IntegerField(choices=enumerate(range(1,8)))
    name = models.CharField(max_length=255)
    level = models.CharField(max_length=7, choices=LEVEL_CHOICES)
    day = models.ForeignKey('Day')

duck monster
Dec 15, 2004

Pants down lads, its time to start whacking off

http://www.optaros.com/blogs/alfresco-django-integration-now-available-google-code

poo poo just got very loving pro. Want to offer your client the ability to edit his site in loving word , and synch it to your django site using the native sharepoint menus? Congratulations champ, you just got a pay rise!

Adbot
ADBOT LOVES YOU

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.

duck monster posted:

Pants down lads, its time to start whacking off

http://www.optaros.com/blogs/alfresco-django-integration-now-available-google-code

poo poo just got very loving pro. Want to offer your client the ability to edit his site in loving word , and synch it to your django site using the native sharepoint menus? Congratulations champ, you just got a pay rise!

This really is brilliant. One of the biggest hurdles the company I work for have faced with Django is actually selling it to clients due to how relatively unknown it is. I've honestly never heard of Alfresco before but looking at their client base this is just the kinda thing we need to pitch Django at an "enterprise" (I just threw up a little) level.

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