Hi,

If I try to import ROLE I get an the error "cannot import name ROLE"

views.py
### CODE ###
def Karateka_edit(request, karateka_id):

    from kav.info.models import Karateka, ROLE

    roles    = [y for x,y in ROLE]

    try:
        karateka  = Karateka.objects.get(id = karateka_id)
    except Karateka.DoesNotExist:
        raise Http404
    return render_to_response('info_karateka_edit.html', {
                                         'karateka'  : karateka,
                                         'roles'       : roles,
                                         'user'      : request.user})
### END CODE ###

Here is my models.py
### CODE ###
class Karateka(models.Model):
    ROLE = (
        ('1', 'Sportler'),
        ('2', 'Nachwuchsteam A'),
        ('3', 'Nachwuchsteam B'),
        ('4', 'Funktionär'),
        ('5', 'Trainer'),
    )
    person    = models.ForeignKey   (Person,            verbose_name = 'Person',
core = True)
    role      = models.CharField    ('Funktion',        blank = True, null =
True, maxlength = 1, choices=ROLE)

    def __str__(self):
        return "%s" % (self.person)

    class Admin:
        list_display = ('person')
        fields = (
            (None,           {'fields': ('person', 'bsc')}),
        )

    def name_last(self):
        return "%s" % (self.person.nameLast)

    class Meta:
        ordering = ('person',)
        verbose_name        = 'Karateka'
        verbose_name_plural = 'Karatekas'

### END CODE ###

Do I have an error in the import syntax? How can I import ROLE?

Thanks for your help
regards,
äL


On 6 Nov., 21:27, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On 11/6/07, äL <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hello Karen
>
> > I have the same problem as Greg has.
>
> > If I try to use your code I got an "page not found" error.
> > Here is my code:
>
> > views.py
> > ### CODE ###
> > def Karateka_edit(request, karateka_id):
>
> >     from kav.info.models import Karateka
>
> >     try:
> >         karateka  = Karateka.objects.get(id = karateka_id)
> >         roles    = [y for x,y in ROLE]
> >     except Karateka.DoesNotExist:
> >         raise Http404
> >     return render_to_response('info_karateka_edit.html', {
> >                                          'karateka'  : karateka,
> >                                          'roles'       : roles,
> >                                          'user'      : request.user})
> > ### END CODE ###
>
> > Do I need to import ROLE like Karateka or do I have an other error in
> > my code?
>
> Yes, assuming ROLE is defined in your models file you will need to import it
> when you want to use it from another file.  But that is not why you got a
> 404 (page not found).  Given that code, you'd only get a 404 if the
> Karateka.objects.get call raises Karateka.DoesNotExist.  So you didn't even
> get as far as the roles= line (there's no reason to include that in the
> try/except btw).  If you had gotten as far as the roles= line and if you had
> not imported ROLE from wherever it is defined, you would have gotten a
> NameError "Global name ROLE is not defined".
>
> Karen


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to