Re: M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-06-24 Thread Victor Hooi
heya,

Nuno: Thanks for the advice.

I know how to add normal inlines to the home page for a model, via the
"inlines" list in admin.py. However, how exactly do I add an inline
formset to the Add Article page?

I can override the template for the Add Article page, however, I don't
think that's what needs to be done here.

Is there a clean way of using the existing "Add Article" page, but
just swapping in an inline for the intermediary? Also, I'd like to
leverage off the exisiting "filter_horizontal" widget, if possible.
Basically, I just want it exactly as it was, without the intermediary,
with a filter_horizontal for settings the m2m relationship, but then
with just an additional widget for setting the intermediary "rating"
field.

(I found this write-up http://www.fictitiousnonsense.com/archives/22
however, it seems geared towards replacing a single field on a single
model, not sure how it'd handle the intermediary model here. Also is
this method still valid/best practice?).

Cheers,
Victor

On May 15, 2:29 am, Nuno Maltez  wrote:
> Hmmm ... you should have an inline formset at the bottom to add firms
> to your Article, with an associated input box forthe rating.
>
> If I understand correctly, each relation Article-Firm now needs a
> rating (mandatory), sou you can't just select Firms from a
> filter_horizontal widget - you need a way to input the rating as well.
>
> Nuno
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-05-14 Thread Nuno Maltez
Hmmm ... you should have an inline formset at the bottom to add firms
to your Article, with an associated input box forthe rating.

If I understand correctly, each relation Article-Firm now needs a
rating (mandatory), sou you can't just select Firms from a
filter_horizontal widget - you need a way to input the rating as well.

Nuno

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



M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-05-13 Thread Victor Hooi
heya,

I have a Django app that keeps track of newspapers articles, and the
companies mentioned in them (this is slightly simplified, but it'

Each article has a m2m relationship with firm. Originally, this was
just a direct m2m, however, I found I needed to add a "rating" to each
firm that's mentioned in an article, hence I created an intermediary
model (FirmRating), which then links Article to Firm.

The relevant models:

class Article(models.Model):
title = models.CharField(max_length=100)
publication_date = models.DateField()
abstract = models.TextField() # Can we restrict this to 450
characters?
category = models.ForeignKey(Category)
subject = models.ForeignKey(Subject)
source_publication = models.ForeignKey(Publication)
page_number = models.CharField(max_length=30)
article_softcopy = models.FileField(upload_to='article_scans',
null=True, blank=True, help_text='Optionally upload a soft-copy (scan)
of the article.')
url = models.URLField(null=True, blank=True, help_text =
'Enter a URL for the article. Include the protocl (e.g. http)')
firm = models.ManyToManyField(Firm, null=True, blank=True,
through='FirmRating')
#firm = models.ForeignKey(Firm)
spokesperson = models.ManyToManyField(Spokeperson, null=True,
blank=True)
#spokesperson = models.ForeignKey(Spokeperson)

def __unicode__(self):
return self.title

class FirmRating(models.Model):
firm = models.ForeignKey(Firm)
article = models.ForeignKey(Article)
rating = models.IntegerField()

class Firm(models.Model):
name = models.CharField(max_length=50, unique=True)
homepage = models.URLField(verify_exists=False,
help_text='Enter the homepage of the firm. Include the protocl (e.g.
http)')

def __unicode__(self):
return self.name

class Meta:
ordering = ['name']

And my admin.py:

class FirmRatingInline(admin.TabularInline):
model = FirmRating
extra = 1

class FirmAdmin(admin.ModelAdmin):
list_display = ('name', 'homepage')
list_editable = ('homepage',)
search_fields = ('name', 'homepage')
inlines = (FirmRatingInline,)

class ArticleAdmin(admin.ModelAdmin):
#inlines = [
#CategoryInline,
#]
date_hierarchy = 'publication_date'
filter_horizontal = ('firm', 'spokesperson')
list_display = ('title', 'publication_date', 'category',
'subject', 'source_publication', 'page_number')
list_editable = ('publication_date', 'category', 'subject',
'source_publication', 'page_number')
list_filter = ('publication_date', 'category', 'subject',
'source_publication')
search_fields = ('title', 'publication_date', 'abstract',
'category__name', 'subject__name', 'source_publication__name',
'page_number', 'url')
inlines = (FirmRatingInline,)

I also read:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models

which provided some info on getting Django admin to play nicely with
intermediary models.

However, I can't seem to get this working on here, I suspect there's
something wrong in the above code

Before, when I was editing articles in the admin (with just a straight
m2m), it offered adding firms to each article in a nice
filter_horizontal widget. However, now, with the intermediary model,
it's like Firm doesn't even exist to Articles anymore, there's no
mention of it on the Article editing page.

There's nothing relevant in the Apache error logs either. I'm a bit
stumped. Any ideas?

Thanks,
Victor

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