Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » New to Django, sheet music organization site [RSS Feed]

#1 Jan. 2, 2011 14:07:26

K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


I am wanting to create an app that helps me organize sheet music. I
want to be able to sort by the artist. Every piece of sheet music I
have I want to be scanned in and uploaded as an image file, then when
I want to open a particular file, it opens as a PDF.

This would be my long terms goals. For now since I am new to Django, I
just want to simply organize my music and be able to easily sort.

I know I will need:

from django.db import models

class Artist(models.Model):
name = models.CharField(max_length=30)
genre = models.CharField(max_length=30)

class Song(models.Model):
name = models.CharField(max_length=30)
artist = models.ForeignKey(Artist)

What else can I do to help me get a start with this? I've gone through
the tutorial and I understand how Django works, its just a matter of
getting some hands on experience.

Thanks for any help.

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

Offline

#2 Jan. 2, 2011 22:56:35

K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


Ok I have a good start. I have run into a problem though. In my
database, I have an artist field. Most artists have a space in there
name. When creating my URLs, how can I ignore white space?

For example, take the artist Chris Tomlin. In my database, it will
show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
to access it, I want to type "music/christomlin" or "music/
chris_tomlin". How can I do this?

Thanks.

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

Offline

#3 Jan. 2, 2011 23:52:48

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


SlugField ?

On Jan 3, 12:56 am, Kyle <kylecoo...@gmail.com> wrote:
> Ok I have a good start. I have run into a problem though. In my
> database, I have an artist field. Most artists have a space in there
> name. When creating my URLs, how can I ignore white space?
>
> For example, take the artist Chris Tomlin. In my database, it will
> show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
> to access it, I want to type "music/christomlin" or "music/
> chris_tomlin". How can I do this?
>
> Thanks.

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

Offline

#4 Jan. 3, 2011 00:08:43

Mike D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


On 3/01/2011 9:56am, Kyle wrote:Ok I have a good start. I have run into a problem though. In my
database, I have an artist field. Most artists have a space in there
name. When creating my URLs, how can I ignore white space?

For example, take the artist Chris Tomlin. In my database, it will
show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
to access it, I want to type "music/christomlin" or "music/
chris_tomlin". How can I do this?Stick to Chris Tomlin everywhere in your database because that is thename you want. Most systems with people names split them into surnameand given name columns but that doesn't seem to make sense in your caseunless you think you will want to search millions of records by separatesurname or given names.The URL however is a different matter. You need to decide how you wantto refer to the artists in a consistent way and put a decorated methodin your artist model something like ...@models.permalink
def get_absolute_url(self):
return "/music/artist/%s/" % self.slug... where self.slug is a field on the artist model where you store therepresentation of the artist's name in exactly the way you want to typeit in as a URL.Note that I added /artist/ to your URL because you will probably want todo something similar for songs and the same principle applies.If you did something like this in your artist model ...

slug = models.SlugField(unique=True)... then the admin app would automatically create the slug for you withhyphens replacing spaces and everything lower-cased. But you need tospecify in the admin app which field is the source for the slug.Otherwise, you could write a method of your own on the artist model tomassage the name as you prefer and populate the slug field when saving arecord.hthThanks.--
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.

Offline

#5 Jan. 3, 2011 03:53:16

K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


Thank you very much! You have been very helpful. I have, however, run
into another problem.

When I try to access my Object, I get an error "invalid literal for
int() with base 10". I know it has something to do with ForeignKeys,
but cannot find how to fix it.

**models.py**------------------------------------------------------------------------------------------------------------------

from django.db import models

# Create your models here.

class Artist(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(unique=True)

def __unicode__(self):
return self.name

class Album(models.Model):
name = models.CharField(max_length=200)
artist = models.ForeignKey(Artist)

def __unicode__(self):
return self.name

class Song(models.Model):
name = models.CharField(max_length=100)
artist = models.ForeignKey(Artist)
album = models.ForeignKey(Album)
date_added = models.DateField('date added')

def __unicode__(self):
return self.name

**views.py**------------------------------------------------------------------------------------------------------------------

from music.models import Song
from django.shortcuts import render_to_response

# Create your views here.

def index(request):
artist = Song.objects.all().order_by('name')
return render_to_response('music/index.html', {'artist': artist})

def artist(request, myartist):
myArgs = Song.objects.all().filter(artist=myartist)
return render_to_response('music/index.html', {'artist': myArgs})

-------------------------------------------------------------------------------------------------------------------------------------

Thanks

On Jan 2, 6:08 pm, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
> On 3/01/2011 9:56am, Kyle wrote:
>
> > Ok I have a good start. I have run into a problem though. In my
> > database, I have an artist field. Most artists have a space in there
> > name. When creating my URLs, how can I ignore white space?
>
> > For example, take the artist Chris Tomlin. In my database, it will
> > show as "Chris Tomlin", but I don't want to type "music/Chris Tomlin"
> > to access it, I want to type "music/christomlin" or "music/
> > chris_tomlin". How can I do this?
>
> Stick to Chris Tomlin everywhere in your database because that is the
> name you want. Most systems with people names split them into surname
> and given name columns but that doesn't seem to make sense in your case
> unless you think you will want to search millions of records by separate
> surname or given names.
>
> The URL however is a different matter. You need to decide how you want
> to refer to the artists in a consistent way and put a decorated method
> in your artist model something like ...
>
> @models.permalink
> def get_absolute_url(self):
>      return "/music/artist/%s/" % self.slug
>
> ... where self.slug is a field on the artist model where you store the
> representation of the artist's name in exactly the way you want to type
> it in as a URL.
>
> Note that I added /artist/ to your URL because you will probably want to
> do something similar for songs and the same principle applies.
>
> If you did something like this in your artist model ...
>
> slug = models.SlugField(unique=True)
>
> ... then the admin app would automatically create the slug for you with
> hyphens replacing spaces and everything lower-cased. But you need to
> specify in the admin app which field is the source for the slug.
>
> Otherwise, you could write a method of your own on the artist model to
> massage the name as you prefer and populate the slug field when saving a
> record.
>
> hth
>
>
>
>
>
>
>
>
>
> > Thanks.

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

Offline

#6 Jan. 3, 2011 12:00:24

Tim S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


On 03/01/11 03:53, Kyle wrote:When I try to access my Object, I get an error "invalid literal for
int() with base 10". I know it has something to do with ForeignKeys,
but cannot find how to fix it.It helps if you post the full stack of the error - we can tell whichline of code it came from then. However,def artist(request, myartist):
myArgs = Song.objects.all().filter(artist=myartist)
return render_to_response('music/index.html', {'artist': myArgs})I think this is your problem. What are you passing in on the url formyartist? Is it a slug?Song.objects.all().filter(artist=myartist)

is expecting myartist to be an Artist instance. Try

Song.objects.all().filter(artist__slug=myartist)

(that's two underscores between artist and slug.)This says "Select me all the songs where the related Artist's slug iswhatever was passed in on the url"Hope that helps,

Tim.

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

Offline

#7 Jan. 3, 2011 12:09:40

Greg T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


On 3 January 2011 23:00, Tim Sawyer <list.dja...@calidris.co.uk> wrote:

> On 03/01/11 03:53, Kyle wrote:
>
>> When I try to access my Object, I get an error "invalid literal for
>> int() with base 10". I know it has something to do with ForeignKeys,
>> but cannot find how to fix it.
>>
>
> It helps if you post the full stack of the error - we can tell which line
> of code it came from then. However,
>
> def artist(request, myartist):
>> myArgs = Song.objects.all().filter(artist=myartist)
>> return render_to_response('music/index.html', {'artist': myArgs})
>>
>
> I think this is your problem. What are you passing in on the url for
> myartist? Is it a slug?
>
> Song.objects.all().filter(artist=myartist)
>
> is expecting myartist to be an Artist instance. Try
>
> Song.objects.all().filter(artist__slug=myartist)
>
> (that's two underscores between artist and slug.)
>
> This says "Select me all the songs where the related Artist's slug is
> whatever was passed in on the url"
>
> And if myartist is an id (and therefore likely an integer or a string of an
integer, as it comes from a URL), then you want:

Song.objects.all().filter(artist__id=myartist)

(the .all() is unneccessary, by the way).

Greg.

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

Offline

#8 Jan. 3, 2011 13:45:33

C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


Good Luck. Just start banging it out. You'll see as you go how much
more there is.

On Jan 1, 11:24 pm, Kyle <kylecoo...@gmail.com> wrote:
> I am wanting to create an app that helps me organize sheet music. I
> want to be able to sort by the artist. Every piece of sheet music I
> have I want to be scanned in and uploaded as an image file, then when
> I want to open a particular file, it opens as a PDF.
>
> This would be my long terms goals. For now since I am new to Django, I
> just want to simply organize my music and be able to easily sort.
>
> I know I will need:
>
> from django.db import models
>
> class Artist(models.Model):
>         name = models.CharField(max_length=30)
>         genre = models.CharField(max_length=30)
>
> class Song(models.Model):
>         name = models.CharField(max_length=30)
>         artist = models.ForeignKey(Artist)
>
> What else can I do to help me get a start with this? I've gone through
> the tutorial and I understand how Django works, its just a matter of
> getting some hands on experience.
>
> Thanks for any help.

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

Offline

#9 Jan. 3, 2011 19:30:02

K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

New to Django, sheet music organization site


Thank you Tim! That was the problem! I will remember to post the full
error stack next time.

Thanks again,
Kyle

On Jan 3, 6:00 am, Tim Sawyer <list.dja...@calidris.co.uk> wrote:
> On 03/01/11 03:53, Kyle wrote:
>
> > When I try to access my Object, I get an error "invalid literal for
> > int() with base 10". I know it has something to do with ForeignKeys,
> > but cannot find how to fix it.
>
> It helps if you post the full stack of the error - we can tell which
> line of code it came from then.  However,
>
> > def artist(request, myartist):
> >    myArgs = Song.objects.all().filter(artist=myartist)
> >    return render_to_response('music/index.html', {'artist': myArgs})
>
> I think this is your problem.  What are you passing in on the url for
> myartist?  Is it a slug?
>
> Song.objects.all().filter(artist=myartist)
>
> is expecting myartist to be an Artist instance. Try
>
> Song.objects.all().filter(artist__slug=myartist)
>
> (that's two underscores between artist and slug.)
>
> This says "Select me all the songs where the related Artist's slug is
> whatever was passed in on the url"
>
> Hope that helps,
>
> Tim.

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

Offline

  • Root
  • » Django
  • » New to Django, sheet music organization site [RSS Feed]

Board footer

Moderator control

Enjoy the 19th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support