Re: Admin interface question

2009-03-30 Thread Phil Edwards

Phil Edwards wrote:
> Hi All:
> 
> First off, apologies if this message ends up appearing twice - I had a 
> minor problem getting Google to recognise that I'd subscribed...
> 

Somehow, I just *knew* that was going to happen... :-)

-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0x68393AEE


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Admin interface question

2009-03-30 Thread Phil Edwards

Hi All:

First off, apologies if this message ends up appearing twice - I had a 
minor problem getting Google to recognise that I'd subscribed...

For my first 'teach myself Django' project, I'm implementing an 
application to manage a software repository. Programs in the repository 
have a category (office, internet, multimedia, etc, etc) associated with 
them and a changelog is maintained showing which items were added to, 
deleted from or changed in each subsequent release of the repository.

I've worked through the tutorials and read some of the online book. I 
have my models defined and the admin interface for my application works 
pretty much the way I want it.

The models look like this:

-begin models.py-
from django.db import models

categoryChoices = (
 (1, 'Security'),
 (2, 'Office'),
 (3, 'Programming'),
 (4, 'Internet'),
 (5, 'Multimedia'),
 (6, 'Miscellaneous'),
)

# Create your models here.
class Program(models.Model):

 ratingChoices = (
 (1, 'Essential'),
 (2, 'Important'),
 (3, 'Nice to Have'),
 (4, 'Geeks Only'),
 )

 category = models.IntegerField(choices = categoryChoices)
 rating = models.IntegerField(choices = ratingChoices)
 name = models.CharField(max_length = 50)
 version = models.CharField(max_length = 15)
 description = models.TextField()
 mainURL = models.URLField(verify_exists = False)
 downloadURL = models.URLField(verify_exists = False)
 installerPath = models.FileField(upload_to = 'downloads')

 def __unicode__(self):
 return str(self.name) + ' v' + str(self.version)

class Release(models.Model):
 version = models.CharField(max_length = 15)
 reldate = models.DateField()

 def __unicode__(self):
 return 'v' + str(self.version) + ' (' + str(self.reldate) + ')'

class ChangeLog(models.Model):
 relVersion = models.ForeignKey('Release')
 category = models.IntegerField(choices = categoryChoices)
 logEntry = models.CharField(max_length = 100)

--end models.py--

My admin interface looks like this:

-begin admin.py-
from django.contrib import admin
from winxpUtils.software.models import Program, Release, ChangeLog

class ProgramAdmin(admin.ModelAdmin):
 list_display = ('name', 'version', 'category', 'rating')
 ordering = ('name',)
 list_filter = ('category', 'rating')
 search_fields = ('description',)

class ChangeInline(admin.TabularInline):
 model = ChangeLog
 extra = 3

class ReleaseAdmin(admin.ModelAdmin):
 list_display = ('version', 'reldate')
 ordering = ('-version',)
 inlines = [ChangeInline]

class ChangeLogAdmin(admin.ModelAdmin):
 list_display = ('relVersion', 'category', 'logEntry')
 ordering = ('category',)
 list_filter = ('relVersion',)

admin.site.register(Program, ProgramAdmin)
admin.site.register(Release, ReleaseAdmin)
admin.site.register(ChangeLog, ChangeLogAdmin)

--end admin.py--

The only thing that I can't figure out in the admin interface is how to 
make my 'TabularInline' bit display the way I want it to. When I go to 
the 'Releases' page, every ChangeLog entry has the title 'ChangeLog 
object' displayed above it. Is there any way to get rid of this? The 
'polls' application in the tutorial doesn't have object names displaying 
like this, but I can't see what I'm doing differently. Just in case my 
explanation isn't clear, I've put a partial screen shot here:

http://www.linux2000.com/django-admin.png

The titles I want to get rid of are circled. Hope this makes sense and 
thanks in advance for any suggestions.

-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0x68393AEE


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: First Django project - Admin question

2009-03-30 Thread Phil Edwards

Daniel Roseman wrote:
> 
> Before answering, I'd point out you have a very significant potential
> bug. Each of your __unicode__ methods actually uses str(). This will

Thank you, that's useful to know - one more item in the (so far!) quite 
empty bag of Django experience!

> Now, on to the question. It's actually related, in that the value that
> gets printed there is the unicode of the inline model. If you want to
> change the value, define a __unicode__ on ChangeLog. But to actually
> remove the value, you'll need to override the inline template. You can
> copy what's in django/contrib/admin/templates/admin/edit_inline/
> tabular.html and just remove lines 25-28. Place the your overridden
> template somewhere in your own templates directory, and put
> template='path/to/your/template.html' in the ChangeInline admin class.

That sort of works - it gets rid of the text, but the space on the page 
that it used to occupy is still there. I've got a better clue where to 
look now, which is good.

Thanks for your help.


-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0x68393AEE


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: .py!

2009-04-17 Thread Phil Edwards

Ionut G. Stan wrote:
> I guess you're coding in Notepad, in which case I'd recommend to look 
> for another editor.

Yup - my favourite for code editing on Windows is PSPad. Free download 
from here:

http://www.pspad.com/en/

Compatible with XP, Vista and Windows7



-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0x68393AEE


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Lookup column value in external dictionary

2009-11-02 Thread Phil Edwards

I've been using Python for some time but I'm new to Django. In one of my 
pet projects to help me up the learning curve, I have a model defined thus:

class Program(models.Model):

 ratingChoices = (
 (1, 'Essential'),
 (2, 'Important'),
 (3, 'Nice to Have'),
 (4, 'Geeks Only'),
 )

 category = models.IntegerField(choices = categoryChoices)
 rating = models.IntegerField(choices = ratingChoices)
 name = models.CharField(max_length = 50)
 version = models.CharField(max_length = 15)
 description = models.TextField()
 mainURL = models.URLField(verify_exists = False)
 downloadURL = models.URLField(verify_exists = False)
 installerPath = models.FileField(upload_to = 'downloads')

This is part of a database of categorised software, the categories being 
1 for 'security', 2 for 'office apps', 3 for programming tools, etc.

I have a simple URL scheme such that '/category/1' pulls up all the 
security related apps, '/category/2' all the office apps and so on.

In the views.py function which deals with this table, I'm using a 
straightforward 'package_list = Program.objects.filter(category = 
thisCategory)' call to pull out the rows I'm interested in for a given 
category.

In addition, each application is rated according to the list defined in 
the 'ratingChoices' tuple in the class definition.

The part of my template which displays the information looks like this:

{% block content %}
 
 {% for package in package_list %}
 
 
 
 
 Website
 Install
 Rating: {{ package.rating 
}}
 
 
 
 {{ package.name }} v{{ package.version 
}}
 {{ package.description }}
 
 
 
 {% endfor %}
{% endblock %}

This all works as expected. The final step that I'm not able to figure 
out is what to put in either the view or the template so that I can do a 
lookup of the 'package.rating' value (which will be 1, 2, 3 or 4) 
against the 'ratingChoices' data so that the final output shows 
something like 'Rating: Important' rather than 'Rating: 2'.

I'd thought of putting these ratings into their own table, although this 
seems a bit of a waste for a short list of data points that will never 
change.

Any help or advice greatly appreciated.

-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: Lookup column value in external dictionary

2009-11-02 Thread Phil Edwards

Phil Edwards wrote:
> 
> This all works as expected. The final step that I'm not able to figure 
> out is what to put in either the view or the template so that I can do a 
> lookup of the 'package.rating' value (which will be 1, 2, 3 or 4) 
> against the 'ratingChoices' data so that the final output shows 
> something like 'Rating: Important' rather than 'Rating: 2'.
> 
> I'd thought of putting these ratings into their own table, although this 
> seems a bit of a waste for a short list of data points that will never 
> change.
> 

As is always the case, 5 more minutes of Googling after posting my query 
and I have the solution!

The answer of course is to replace:

Rating: {{ package.rating }}

with this:

Rating: {{ package.get_rating_display 
}}

Onwards and upwards!


-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Multiple URLs, Common View

2010-07-18 Thread Phil Edwards

Hi All:

I've written myself an ultra-simple CMS as a Django learning exercise. 
It consists of a couple of simple models and a single template to serve 
up articles which have previously been posted into the database from the 
admin interface.


Everything seems to work okay, but I think my implementation could be 
better. I have a single view function which at present looks like this:


-begin-
def servePage(request):
if request.path[1:] == '':
thisPage = Page.objects.get(name = unicode('home'))
else:
thisPage = Page.objects.get(name = unicode(request.path[1:]))
sidebar_list = Page.objects.filter(category = thisPage.category)
article_list = Article.objects.filter(page = 
thisPage.id).order_by('-amendedon')

return render_to_response('base.html', locals())
--end--

Firstly, I suspect that my use of request.path[:1] to get the URL being 
accessed is not the accepted Django way. Is there a better method?


Secondly, even with the generic view that I'm using, I still need to 
have multiple entries in my urls.py file in order to make pages work, i.e:


urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
('^$', servePage),
(r'^home$', servePage),
(r'^about$', servePage),
(r'^family$', servePage),
(r'^aviation$', servePage),
(r'^linux$', servePage),
(r'^windows$', servePage),
(r'^coding$', servePage),
(r'^photo$', servePage),
(r'^gallery$', servePage),
(r'^ppl-diary$', servePage),
)

Is there a way to replace this with a catch all pattern which does not 
break other things? I've tried patterns such as r'^' and this simply 
leads to my static content being skipped, so I see the pages, but with 
no stylesheet applied and all images missing.


I'm seeing a tantalizing clue from the 404 page that gets generated when 
I have DEBUG = True in my settings file. When Django tells me what URL 
patterns it tried, the very last one is "^static/(?P.*)$" - I 
suspect that if I knew how to incorporate that into my urls.py ahead of 
my 'catchall' pattern, I'd be good to go...


I've Googled for terms like 'django generic view' and 'django multiple 
url single view' but I can't find anything useful. I think that at this 
level, my setup probably doesn;t matter, but if it does I'm using Django 
1.2 on both Windows XP and Linux, with Python 2.7 and 2.6 respectively, 
depending upon which machine I have my USB stick plugged into at the time.


--

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500

--
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: Multiple URLs, Common View

2010-07-18 Thread Phil Edwards

On 18/07/2010 23:55, Phil Edwards wrote:


-begin-
def servePage(request):
if request.path[1:] == '':
thisPage = Page.objects.get(name = unicode('home'))
else:
thisPage = Page.objects.get(name = unicode(request.path[1:]))
sidebar_list = Page.objects.filter(category = thisPage.category)
article_list = Article.objects.filter(page =
thisPage.id).order_by('-amendedon')
return render_to_response('base.html', locals())
--end--



Meh. Don't know what happened to the indentation there, but it should 
look like this:


-begin-
def servePage(request):
if request.path[1:] == '':
thisPage = Page.objects.get(name = unicode('home'))
else:
thisPage = Page.objects.get(name = unicode(request.path[1:]))
sidebar_list = Page.objects.filter(category = thisPage.category)
article_list = Article.objects.filter(page = 
thisPage.id).order_by('-amendedon')

return render_to_response('base.html', locals())
--end--

--

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500

--
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: Multiple URLs, Common View

2010-07-22 Thread Phil Edwards
On 20/07/10 13:01, joconnell wrote:
> Hi,
> 
> If you use something like
> 
> r'^(?P.+)/$'
> 
> then a variable called page will get passed to your view. It will
> contain the string that has been matched against the specified pattern
> (in this case any character 1 or more times (.+))
> 

Thanks John and everyone else who replied - the regex above did the
trick for me. I've now got the whole site running from just a single
view called servePage, and I don;t have to update my URL list each time
I add a new page to the database, which was exactly what I wanted.

Thanks again folks!


-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500

-- 
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.