The admin interface - this used to work?

2009-08-18 Thread Joakim Hove

Hello,

I am slowly building up a site with django - it feels very good.

About two months ago I tried the admin interface; with nearly zero
effort (basically uncomment a couple of lines from the default files)
I got a very nice and functional interface up and running - great!

Now I have done some changes, and can not get the interface to work
any longer. What I have done is:

  1. I have moved to the production server, and django is invoked with
apache & mod_wsgi (previously used the dev server).
  2. I have upgraded django to the latest svn release (I had latest
svn in june as well).
  3. I have not installed any admin.py files.

When I now go to the admin url I can log in with the django super user
account, but:

  1. The interface is damn basic - maybe some stylesheets / templates
are missing?
  2. The interface does not seem to contain any information about my
site anymore.

Any tips?

Joakim

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



Showng the primary key in admin view

2009-09-01 Thread Joakim Hove

Hello,

I have a (simplified) model like this

class Customer(models.Model):
 name  =   models.CharfField(max_length = 100)
 date=   models.DateTimeField()
 email  =   models.EmailField()


When showing this in the (100 % default) admin view I get up nice
entry boxes for the fields 'name', 'date' and 'email'. In addition I
would very much like to display the 'id' field which django has
automatically added (preferably as readonly). Any tips on how to
achieve this?

Joakim
--~--~-~--~~~---~--~~
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: Showng the primary key in admin view

2009-09-02 Thread Joakim Hove

Thank you both for answering; however I am afraid we are
misunderstanding eachother here.

I have created a admin.py file and registered my CustomerClass with
the admin interface. That works, and I can select the CustomerClass
when logged in to the admin interface.
Let us say I have created three instances of the CustomerClass class,
with primary keys ranging 0..2 - then using the __unicode__() function
suggested below I am presented with a list of three items:

  0: John
  1: Bill
  2: George

Clicking on "2: George" I get up a new screen where I can edit the
information about George:

  Name:  [  George ]
  Date  :  [ 27/08/2009 ]
  Email:  [ geo...@mail.com ]

Now - it is in this view I would have liked to display the primary key
as well (the primary key serves as kind of customer id). I have tried
to instantiate a CustomerAdmin class and listed the "id" field, there
but that only gives run time error. It seems the admin view/template
does not recognize the id which is an AutoField.

OK - thanks a lot for your time - further suggestions greatly
appreciated!

Joakim





--~--~-~--~~~---~--~~
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: Showng the primary key in admin view

2009-09-02 Thread Joakim Hove

> and if you look up-screen at the "breadcrumbs" you should see ...
>
> Home >> Customers >> 2: George
>
> Does that do it?

Well - I know (and thanks for the info) - but I would really like to
get it even clearer.

Joakim

--~--~-~--~~~---~--~~
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: Showng the primary key in admin view

2009-09-02 Thread Joakim Hove



Hello,

thanks for the tip:

> It is usually not a good idea to give business meaning to a primary key
> in a relational database. The literature is full of reasons against it.

I had a nagging feeling this might be the case. Do you have any links
to "Best practice" om these questions - I am a database freshman.

Thanks - Joakim
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Rendering a form based on partly determined model state

2009-05-21 Thread Joakim Hove

Hello,

I have just started using Django - looks very promising!

I am trying to implement  something resembling a web-based shop. A
simplified overview of my situation is as follows:

models.py
---

class Country(models.Model)
 name = CharField(max_length  = 100)
 currency = CharField(max_length  = 3)


class Product(models.Model)
  name   = CharField(max_length = 100)
  price = FloatField()
  country = ForeignKey(Country , editable = False)


class Transaction(models.Model)
  country   = ForeignKey( Country , editable = False)
  product  = ForeignKey( Product )
  date= DateField()

views.py
---

class NewTransaction(ModelForm):
   class Meta:
model = Transaction

def newtransaction(request , country):
   return render_to_response(...)

...
Now, an important aspect of this shop is that it operates in several
different countries, and the available product are different in
different countries. The database can typically contain four Product
objects:

 ["Norwegian_Product1" , "Norwegian_Product2" ,
"Swedish_Product1" , "Swedish_Product2"]

Based on the url the customer used I know which country she is in, and
whether I should present the Norwegian products or the Swedish
product. This id comes as the second argument to the view function,
but when rendering the NewTransaction form I do not understand how to
limit the rendereing ov available product to only those available in
the customers country?!


Any tips greatly appreciated.

Regards

Joakim Hove




--~--~-~--~~~---~--~~
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: Rendering a form based on partly determined model state

2009-05-21 Thread Joakim Hove

I found Collin's Blog entry, and that looked very promising.

Thanks a lot.

Joakim
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Setting the label on selection widget

2009-05-25 Thread Joakim Hove

Hello,

I am implementing a simple 'shop'. The (simplified) model consists of
these classes:


class Product(models.Model):
   name = models.CharField(max_length = 100)


class Country(models.Model):
   currency = models.CharField(max_length = 3)


class Price(models.Model):
   product = models.ForeignKey( Products )
   country = models.ForeignKey( Country )
   price = models.FloatField()


The product to buy is selected from a  widget. I would like
the label displayed on the widget to be something like:

   "%s   %s %s" % (product.name , country.currency , price
(product , country))

The country comes from the url the customer has used to access the
page, but I wonder how to pass this value to the function rendering
the label for the selevct widget? And furthermore: currently I am
adjusting the __unicode__() function of the Products class to
manipulate this rendering; is it possible to the rendering to use
another function (I am currently just rendering the form with
xxx.as_table()).

Best Regards


Joakim Hove


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



What is in your opinion the best way to render a form

2009-05-25 Thread Joakim Hove

Hello,

I have used ModelForm to create a form for a model class. In the
template rendering the form I just have:

form.as_table

that is very neat, compared to writing out all the form elements in
the template manually, but it is of course not as flexible. What is
the common thing to do?

Joakim
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Primary key defined by two foreignkeys?

2009-06-07 Thread Joakim Hove

Hello,

I have the following (schematic) situation:

Class Table1(models.model):




Class Table2(models.model):
   
   



class Table3(models.model):
  table1_key = models.ForeignKey( Table1 )
  table2_key = models.ForeignKey( Table2 )
  .



Now, I want the two foreign keys in Table3 (in combination) to be a
unique id, i.e. it should be illegal to have several entries in Table3
pointing to the same combination of Table1 and Table2 keys. This
should be doable?!

Best Regards

Joakim Hove

--~--~-~--~~~---~--~~
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: Primary key defined by two foreignkeys?

2009-06-07 Thread Joakim Hove


> Use unique_together:http://docs.djangoproject.com/en/dev/ref/models/options/
>
> class Table3(models.Model):
>     ...
>     class Meta:
>         unique_together = ("table1_key", "table2_key")

Beautiful - thank you very much :-)

Joakim
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



User logged in by default??

2009-06-15 Thread Joakim Hove

Hello,

I have just started experimenting with the Django user authentication
system, I am currently only running with the Python testserver (if
that matters). In my url.py file I have the following view mapping:

...
(r'^agent/$'  ,   'Sleipner.model.views.agent'),
.

This view looks like this:


def agent(request):
 if not request.user.is_authenticated():
 return HttpResponseRedirect('/Sleipner/login/?next=%s' %
request.path)
 else:
 return render_to_response("model/agent.html" , {"username" :
request.user.username})


I.e. if the current request does not come from a authenticated user
the view should redirect to a page querying for login info, otherwise
it should render a simple page which displays the username of the
currently logged in (authenticated) user. Now, what I do not
understand is that the agent() function above always seems to execute
the second code branch, i.e. it renders a welcome message to the
agent, with a valid username, without me ever logging in? It ssems a
user is automatically logged in - without any effort on my behalf.

The logout() function also fails with "maximum recursion depth
exceeded" - which might indicate some auto-login behaviour?

Any tips greatly appreciated!

Joakim

--~--~-~--~~~---~--~~
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: User logged in by default??

2009-06-15 Thread Joakim Hove

Hello,

thank you for answering.

> Did you log yourself in in the admin without thinking about it?  That's
> usually how I end up logged in without realizing it.

I had thought of that - and did a fresh start of the browser without
any success. But, prompted by your suggestion I continued to remove
all cookies, and then it worked (i..e I was presented with the login
view I expected).

Thanks - Joakim
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Queryset filtering based on user supplied callable??

2010-06-05 Thread Joakim Hove
Hello,

I have a query list which I want to filter based on a computation
which I supply:


# Create a query set containing everything:
obj_list = MyObject.objects.all()


# Now - select only the element which pass some test:
obj_list = obj_list.filter( my_filter )


def my_filter( obj ):
 # Does a computation based on obj values, and returns true or
false
 
 return true|false

Is something like this doable?

Joakim

-- 
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: Queryset filtering based on user supplied callable??

2010-06-05 Thread Joakim Hove
Thank you very much :-)

Joakim

On Jun 5, 4:42 pm, johan de taeye  wrote:
> Typo...
> The correct syntax is :
>     obj_list = [ i for i in MyObject.objects.all() if my_filter(i) ]
>
> On Jun 5, 4:29 pm, johan de taeye  wrote:
>
> > Possible through basic Python:
>
> >   obj_list = [ i for i in MyObject.objects.all() where my_filter(i) ]
>
> > Note that this filtering is happening on the Python side of things,
> > whereas a queryset filter is executed in SQL on the database.  The
> > filtering on the database is normally much, much faster, so be careful
> > with the python-style filtering...
>
> > Johan
>
> > On Jun 5, 12:32 pm, Joakim Hove  wrote:
>
> > > Hello,
>
> > > I have a query list which I want to filter based on a computation
> > > which I supply:
>
> > > # Create a query set containing everything:
> > > obj_list = MyObject.objects.all()
>
> > > # Now - select only the element which pass some test:
> > > obj_list = obj_list.filter( my_filter )
>
> > > def my_filter( obj ):
> > >      # Does a computation based on obj values, and returns true or
> > > false
> > >      
> > >      return true|false
>
> > > Is something like this doable?
>
> > > Joakim- Hide quoted text -
>
> > - Show quoted text -

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



Unicode challenged

2010-08-09 Thread Joakim Hove
Hello,

I am developing a Django application, and have some Unicode problems.
I must admit I do not really understand if my problems are with Django
or Python or ... ; but hopefully someone her can shed some light on
the problem.

Setup:

1. The application is developed for the Scandinavian countries, and
will typically handle various Scandinavian letters like æåø.

2. I am developing everything on Ubuntu Linux.

3. I am using MySQL as database, currently the character_set is set to
(the default) latin-1; but I can of course change that.


What happens:

1. A user fills out a form containing one of the problematic
characters like 'Å'.

2. Django is used to validate the form, and the form content is saved
in the MySQL database.

3. I have a view fetching the content from the database, and returning
it to a users browser with the render_to_response() function.

4. In addition to rendering the template as browser output I want to
store the rendered output in a file (as a hardcopy). This fails with
UnicodeDecodeError. The code which fails look schematically like this:


template = 
context = 
string_content = render_to_string( template , context )
fileH = open( filename , "w")
fileH.write( string_content )  <--  This fails.
fileH.close()


Now - the code which works exactly as it should, i.e. 3. above, is
nearly identical but the function render_to_output() is used instead,
and no file operations. How does the browser (firefox 3.??) magically
get this right?

I have also tried replacing the write() statement with
write( string_content.encode( '' )) where I have tried the
encodings 'latin-1' and 'utf-8'; then it does not fail hard, but
instead of the wanted 'øåæ' characters I get '?' marks.

Any tips on this greatly appreciated.

Joakim





-- 
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: Unicode challenged

2010-08-09 Thread Joakim Hove
Thank you for answering;

> Are you sure that you get '?' on the file if you write it this way, or
> it's just
> the console/editor that you're using to see the file's contents that
> cannot handle
> the text's encoding?

When it comes to Unicode and such I am not sure about anything. But
you are probably right; I redid everything very carefully with 'utf-8'
encoding now, and that seemed to work OK.

Thanks.

Joakim

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



Automatic form submission and CSRF??

2010-09-26 Thread Joakim Hove
Hello,

I have a simple form which has method POST. When I view the form in
the browser and fill it normally everything works fine. However; the
plan is to submit this form automagically from a client program - I
have currently tried with the Python script:

#!/usr/bin/python
import urllib
params = urllib.urlencode({"passwd": "Hemmelig",
   "user_id" : 1000,
   "subject" : "Tema",
   "extra_addr" : "joakim-h...@gmail.com",
   "date_list" : "10-10-2010",
   "body" : "Lang melding"})

f = urllib.urlopen(form_url , params)
print f.read()

The server just returns error code 403: "No CSRF or session cookie";
how can I get around this? Do I have to create a csrfmiddlewaretoken
on the client (which will not even have Python installed)?

-- 
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: Automatic form submission and CSRF??

2010-09-26 Thread Joakim Hove
Thanks a lot - that did the trick!

Joakim

On Sep 27, 1:58 am, Russell Keith-Magee 
wrote:
> On Mon, Sep 27, 2010 at 12:18 AM, Joakim Hove  wrote:
> > Hello,
>
> > I have a simple form which has method POST. When I view the form in
> > the browser and fill it normally everything works fine. However; the
> > plan is to submit this form automagically from a client program - I
> > have currently tried with the Python script:
>
> > #!/usr/bin/python
> > import urllib
> > params = urllib.urlencode({"passwd": "Hemmelig",
> >                           "user_id" : 1000,
> >                           "subject" : "Tema",
> >                           "extra_addr" : "joakim-h...@gmail.com",
> >                           "date_list" : "10-10-2010",
> >                           "body" : "Lang melding"})
>
> > f = urllib.urlopen(form_url , params)
> > print f.read()
>
> > The server just returns error code 403: "No CSRF or session cookie";
> > how can I get around this? Do I have to create a csrfmiddlewaretoken
> > on the client (which will not even have Python installed)?
>
> If it's impractical or impossible to get access to the CSRF token by
> GET before POSTing, you can disable CSRF on that single view. See [1]
> for details.
>
> [1]http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#exceptions
>
> Yours,
> Russ Magee %-)

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



Embed the file system path to a template??

2010-10-24 Thread Joakim Hove
Hello,

to assist those responsible for the content of "my" site I would like
to embed the file-system path to the template in the rendered
template, so that when they find something they are dissatisfied with
on a page they can do "View Source" and easily identify the correct
template to update.

I.e. I would like to embed something like this at the top of all the
templates:



Is this possible?

Joakim

-- 
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: Embed the file system path to a template??

2010-10-25 Thread Joakim Hove

> However, if you just want to know the top-level template that started
> the rendering process, you could obtain this by writing a custom
> render_to_template() shortcut that inserts the loaded template name
> into the context.

Thank you,

 I considered writing this custom render_to_template() shortcut, but
hoped maybe there was a simpler solution. I will be using this custom
shortcut quite extensively - i.e. I would like existing code which
currently calls render_to_response() to change over to my new shortcut
without updating every call. Is there a reasonably elegant way to
achieve this?

Joakim

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



Django based issue tracker

2010-11-10 Thread Joakim Hove
Hello,

I am setting up a bug/issue tracker - the project is quite small and I
do not have complex needs. As I enjoy working with Django I was
looking for a Django based solution. Can someone reccomend a Django
based issue tracker?

In case I fail finding something based on Django I think I will use
Trac which seems quite nice.

Joakim

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



Debug internalization

2010-12-03 Thread Joakim Hove
Hello,

I am trying to use Djangos internalization framework - but struggling
a bit ...

In my settings.py file I have:

LANGUAGES = (
("en" , ugettext("English")),
("no" , ugettext("Norwegian")),
("sv" , ugettext("Swedish")),
("dk" , ugettext("Danish")))

LANGUAGE_CODE = 'en-us'


MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
.


In my view I have:


from django.utils.translation   import ugettext

def view_local(request):
  msg = ugettext("Local message")
  return render_to_context()


Now my problem is that the ugettext() function will only return the
literal input string, whatever I pass it. In the beginning I of course
passed in strings I had a translation for, but e.g.

msg = ugettext("Message_without_any_translation")

will just work "fine". So I guess I wonder if it is possible to get
some debug info from this, i.e. in development mode I would prefer the
ugettext() function to crash and burn if the msgid can not be found
instead of just return the msgid. Any tips on this?



Regards Joakim




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



Visual appearance (i.e. templates) for admin site

2010-01-31 Thread Joakim Hove
Hello,

I am starting to get up to "speed" with Django - and I really like it!
Now I have a  question about the visual appearance of the admin site.
When I first tried the admin site a couple of months ago it looked
"very nice"; since then the code has been rewritten from scratch and I
don't have anything of those first fumbling attempts any longer (I
have vc now ...). When I now activate the admin site it works nicely,
but looks extremely basic, i.e. it can seem like I have "lost" some
nice looking templates for the admin site?

I am using an svn version of Django (as of a couple of weeks ago), and
my admin site is 100% plain vanilla. Does anyone have an idea why my
admin site now looks so basic, when it was much nicer before?

Joakim

-- 
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: Visual appearance (i.e. templates) for admin site

2010-01-31 Thread Joakim Hove
Thank you -

 that seems like a very reasonable explanation. When things worked
previously I was using the built in dev-server, whereas I am now using
Apache + WSGI.



On Jan 31, 9:07 pm, Daniel Roseman  wrote:
> On Jan 31, 7:32 pm, Joakim Hove  wrote:
>
>
>
> > Hello,
>
> > I am starting to get up to "speed" with Django - and I really like it!
> > Now I have a  question about the visual appearance of the admin site.
> > When I first tried the admin site a couple of months ago it looked
> > "very nice"; since then the code has been rewritten from scratch and I
> > don't have anything of those first fumbling attempts any longer (I
> > have vc now ...). When I now activate the admin site it works nicely,
> > but looks extremely basic, i.e. it can seem like I have "lost" some
> > nice looking templates for the admin site?
>
> > I am using an svn version of Django (as of a couple of weeks ago), and
> > my admin site is 100% plain vanilla. Does anyone have an idea why my
> > admin site now looks so basic, when it was much nicer before?
>
> > Joakim
>
> I presume you are not serving any of the CSS. Read 
> this:http://docs.djangoproject.com/en/1.1/howto/static-files/#howto-static...
> --
> DR.

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



When does syncd create new tables

2010-02-04 Thread Joakim Hove
Hello,

I am developing my models. I have quite a lot of legacy data which I
have to take into account, so I try hard to understand the logic of
syncdb. My current situation is as follows:

  1. I had written the model defintion of several models in Python and
created the corresponding tables with "./manage.py syncdb".
  2. I then realized that I needed to change the model definitions
somewhat. Then I:
   a) Deleted the databes tables manually, using a regular
databese client. I did not touch tables like ~ auth_user.
   b) I updatet my models.py files.
   c) I tried to recreate the tables with "./manage.py syncdb" -
but to no avail, nothing happened?

Any tips on what I am doing wrong greatly appreciated.

Joakim

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



Is the user member of a certain group

2010-02-22 Thread Joakim Hove
Hello,

using the django auth framework I have created two groups called
"admin" and "normal" and all the users are members of either of these
groups. Now when a user is authenticated I would like to render
different views depending on which group the user is member of,
something like this:


if user_is_member_of_admin_group():
   render_to_response("admin_template.html", context)
elif user_is_member_of_normal_group():
   render_to_response("normal_template.html , context)
else:
   hmmm - internal applcation error!


Any tip on how to write the "user_is_member_of_admin_group()"
function?


Joakim

-- 
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: Is the user member of a certain group

2010-02-22 Thread Joakim Hove
Thank you both;

it works!

Joakim

On Feb 23, 12:27 am, Andy McKay  wrote:
> On 2010-02-22, at 2:56 PM, Joakim Hove wrote:
>
> > Any tip on how to write the "user_is_member_of_admin_group()"
> > function?
>
> You can access the groups via the ManyRelatedManager, which exposes a 
> queryset: user.groups.filter(...)
>
> eg: if user.groups.filter(name="Admin")
> --
>   Andy McKay, @clearwind
>  http://clearwind.ca/djangoski

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



Unicode and localized characters in view

2010-03-03 Thread Joakim Hove
About every once a year I am forced out on the internet to read about
"encodings and such"; while reading about it all makes sense, but when
actually trying to get things to work I always go through a period of
swearing and frustration - I never really get it :-(

Now, in a Django view I have a selectionlist, and one of the seletions
should contain the Norwegian problem child 'å'. I have tried the
following:

1, I have explicitly used the HTML syntax å - however in this
case Django ended up rendering the '&' as '&', i.e. as if I wanted
a literal '&'.

2. I just entered the 'å' in the Python source code for the view. Then
a get a Python run.-time error stating that I must declare an encoding
when using non-ASCII characters. I then tried declaring the encoding
'latin-1' in the top of the source file of the view, this gave a
UnicodeDecodeError triggered by Django:

'ascii' codec can't decode byte 0xe5 in position 14: ordinal
not in range(128)


Any hints?


Joakim

-- 
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: Unicode and localized characters in view

2010-03-04 Thread Joakim Hove
Thank you for answering; I had a feeling that some autoescape magic
might be at work.


Unfortunately I do not have the code here, but the django traceback
goes like this:


Environment:

Request Method: GET
Request URL: http://devel.pc-horse.com/NewLicense/47/
Django Version: 1.2 beta 1 SVN-12494
Python Version: 2.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'sleipner.config',
 'sleipner.main',
 'sleipner.transactions',
 'sleipner.DIBS']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  101. response = callback(request,
*callback_args, **callback_kwargs)
File "/var/www/Django/devel/sleipner/main/license.py" in new
  58. form = NewLicenseForm( country )
File "/var/www/Django/devel/sleipner/main/license.py" in __init__
  36. productList.append( (p.id , "%s %s %6.0f %s" %
(type.localized_name(country.id) ,
dur.localized_duration(country.id) , total_price , currency )) )
-

The return value from the function "dur.localilized_duration( )"
contains a "å" and that is what it brings it down. I have certainly
declared encoding in the source file which contains the implementation
of this function (which contains a literal "å"), but come to think of
it I might have forgotten to declare endcoding of the source file
which is actually running when it crashes?

Joakim


On 4 Mar, 08:48, Daniel Roseman  wrote:
> On Mar 4, 6:45 am, Joakim Hove  wrote:
>
> > About every once a year I am forced out on the internet to read about
> > "encodings and such"; while reading about it all makes sense, but when
> > actually trying to get things to work I always go through a period of
> > swearing and frustration - I never really get it :-(
>
> > Now, in a Django view I have a selectionlist, and one of the seletions
> > should contain the Norwegian problem child 'å'. I have tried the
> > following:
>
> > 1, I have explicitly used the HTML syntax å - however in this
> > case Django ended up rendering the '&' as '&', i.e. as if I wanted
> > a literal '&'.
>
> Nothing to do with encodings, this is autoescaping at work. 
> Seehttp://docs.djangoproject.com/en/1.1/topics/templates/#id2
>
> > 2. I just entered the 'å' in the Python source code for the view. Then
> > a get a Python run.-time error stating that I must declare an encoding
> > when using non-ASCII characters. I then tried declaring the encoding
> > 'latin-1' in the top of the source file of the view, this gave a
> > UnicodeDecodeError triggered by Django:
>
> >         'ascii' codec can't decode byte 0xe5 in position 14: ordinal
> > not in range(128)
>
> > Any hints?
>
> Please show the code.
> --
> DR.

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



Passing (validated) form content to the next view.

2010-03-09 Thread Joakim Hove
Hello,

I am implementing a small system which (simplified) should be like
this:

1. The user enters some information in a form.
2. The form content is validated.
3. The user is redirected to a new page (pure HTML / form ??)
summarizing
the information in the first form, and given the choices:
 A: Go back and correct the information.
 B: Confirm that the information is correct. (In this case I plan
to hit the database with updated information).


Currently the code looks roughly like this:
--
def InputForm( forms.Form ):
 name = forms.CharField( max_length = 100)
 email = forms.EmailField( )


# This is the view called in 1 above (have omitted some csrf magic).
def initial_view( request ):
  if request.method == "GET":
   form = InputForm()
  else:
   form = InputForm( reques.POST )
   if form.is_valid():
return HttpResponseRedirect( "/last_chance/" , )
>\
return render_to_response( "form_template.html" ,
request )   |
 
|
 
|
# In this view I would like to display the input the user entered in
the previous form.  |
def last_chance_view( request ):
<--/
  return render_to_response()??
--

Now; the question I have is how to pass the validated input values
(i.e. name and email) from initial_view() on to the last_chance_view()
(as indicated with the ASCII arrow in the code above).

Joakim


-- 
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: Passing (validated) form content to the next view.

2010-03-09 Thread Joakim Hove
Sorry;

my attempts at interlacing ASCII art in the code did not exactly
aid readability. Here is the code section again, simplified:

--
def InputForm( forms.Form ):
 name = forms.CharField( max_length = 100)
 email = forms.EmailField( )


# This is the view called in 1 above (have omitted some csrf magic).
def initial_view( request ):
  if request.method == "GET":
   form = InputForm()
  else:
   form = InputForm( reques.POST )
   if form.is_valid():
return HttpResponseRedirect( "/last_chance/" , )
return render_to_response( "form_template.html" ,
request )

# In this view I would like to display the input the user entered in
# the previous form.
def last_chance_view( request ):
  return render_to_response()??

 
--

Joakim

-- 
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: tutorial --> deploy snag

2010-03-09 Thread Joakim Hove
Hello,

I __think__ you must add the path industtromatic_com in your wsgi
settings file,

> The line
> os.environ['DJANGO_SETTINGS_MODULE'] = 'industromatic_com.settings'
> refers to a dir I made, /home/john/WEBprojects/industromatic_com, that I 
> copied the
> contents of mysite into.  mysite as it was at the end of the tuturial.

i.e. something like:

import sys
sys.path.append( "/home/john/WEBprojects/industromatic_com" )
os.environ["DJANGO_SETTINGS_MODULE"] = 'industromatic_com.settings'


HTH - Joakim

-- 
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: tutorial --> deploy snag

2010-03-10 Thread Joakim Hove

> What have I left out of this Virtualhost configuration?


Warning: This is a the very limit of my understanding of Django; but I
have the following
section in my apache configuration file; I see you have already
aliased media to point somewhere
else.

   Alias /media/ "/usr/local/django/django/contrib/admin/media/"
   
  Order allow,deny
  Options Indexes
  Allow from all
  IndexOptions FancyIndexing
   

HTH - Joakim

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



Conflict between django csrf and credit card clearing?

2010-03-17 Thread Joakim Hove
Hello,

I am using Django to write a sort of web-shop site. For reading
credit
card information, and reserving the money we use a third part company
called DIBS. The flow of the application is roughly like this:

1. The customer peeks around at our site and selects product(s) to
buy.

2. When the customer is ready to commit she is redirected to the site
of
the third party. The URL redirecting there contains some
information
about the purchase, i.e. the amount, an order id in our system
and
so on.
In addition the url contains three extra URLs which the DIBS
system
will redirect to, depending on the outcome of the transaction.

3. When a transaction has completed successfully DIBS will redirect
the
customer to a URL like this on my site:

http://what.ever/DIBS/accept/d/

The url mapping of this is just to a simple view function
displaying a
"Thank you for your purchase blablabla" text. Now this page is not
rendered, instead I get 403 and CSRF verification failure.
Now the view I would like to render in this case is not a form, so
I do
not really understand how the csrf macinery of Django comes into
play?

Summary of redirections:

  Form at my site --> DIBS --> simple view at my site.

Any tips?


Joakim



-- 
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: Conflict between django csrf and credit card clearing?

2010-03-17 Thread Joakim Hove
Hello Peter,

thank you very much for your answer. The exception did the job :-)

Joakim

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



Is the DoesNotExist exception the only way to check if an object exists?

2010-04-09 Thread Joakim Hove
Hello,

I have something I would presume was a very common pattern. I have a
view which gets a primary-key (from the user) as second argument:


def my_view( request , pk ):
 obj = Class.objects.get( pk = pk)
 # Do something with obj and return a suitable response.


Now, of course I would like to check whether the object identified by
'pk' is in the database, and return a suitable error message if that
fails; I was halfway expecting to find a "has_key() / exists() / ..."
method, but it seems the only way to handle this gracefully is by
catching the DoesNotExist exception?

I have never really got very friendly with exceptions, I tend to
consider them as something exceptional which "should not" happen,
whereas the fact that the database does not contain a particular key
is in my opinion something quite ordinary and not by any means
"exceptional".

Or maybe I am misunderstanding roally here?

Joakim


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



Long usernames in auth_user?

2011-10-26 Thread Joakim Hove
Hello,

I have been using a (in general quite popular I think ...) convention
where the e-mail address has been used as username. I have solved this
by asking the user for an e-mail address and a password, and then used
the supplied e-mail address both as username and e-mail address when
instantiating a User object. This has worked fine up until now.

Now suddenly someone came along with an e-mail address which was
longer than the 30 characters limit imposed on the username; and
things went to pieces. I have Googled this topic but did not find any
clear cut simple solution, altough I am definitely not the first one
to stumble over this problem.

So two questions:

1) I modified the (development) database directly increasing the field
size from 30 to 75; and that seemed to work nicely; but I am not very
comfortable about the solution. What do you say?

2) Any chance of changing this in a future release?

Joakim

-- 
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: Long usernames in auth_user?

2011-10-26 Thread Joakim Hove
OK;

thanks I was afraid it was not entirely straightforward.

On Oct 26, 10:52 pm, Donald Stufft  wrote:
> This is a known limitation and it's something that people _want_ to get fixed 
> (but just merely increasing the length isn't helpful, because soon someone 
> comes along with the new length + 1 and the same problem occurs).

Now - of course the problem can easily crop up again by just
increasing length; but if the username length and the email length at
least default to the same value (the email field has length 75) the
failure will at least be simultaneous - and the usage pattern I
describe will work until the 75 characters e-mail limit is reached. So
although by no means a full solution, increasing the username length
to 75 would in my opinion be a very simple fix with some benefit?

Joakim

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



Form with two select boxes + javascript - selection gets destroyed???

2011-04-15 Thread Joakim Hove
Hello;

I have a problem with a Django using JavaScript which I really don't
understand. It must be said that this is my first time using
JavaScript to beef up my forms - that might be source of the problem.

The form presents the user with two drop down selectors and a submit
button like:

 Country: [--]
 Product: [--]

 [ Submit ]


Now the available products are not the same in the different
countries, so when the user has selected a country the browser will
javscript to ask the server for a list of products available in that
country. This seems to work, at least the product selection box is
automatically updated with seemingly correct values. When I am happy
with both the country and product selection I hit the submit button
and everything goes to the server running django.

For this particular form I have a clean() method which verifies that
the chosen product is indeed available in the chosen country (the
client side javascript should ensure that already, but anyway):

 def clean( self ):
 product_id = self.cleaned_data.get("product_id")
 country_id = self.cleaned_data.get("country_id")

 product = Product.objects.get( pk = product_id)<
This fails with Object not found.

As indicated the clean() method fails, and inspection of the DEBUG
traceback reveals that product_id has the value 'None' - however
looking at the POST data also present on the DEBUG traceback shows
that product_id has a reasonable value??? So to me it seems that
somewhere along the way, the product_id variable is lost?

Some other observations:
1. If just dropping the javascrip altogether - i.e. potentially
allowing for a product/country mismatch the django application works
as intended.
2. If I only change one of the selectors at a time things also work
nicely. It is possible to select a product "No product" which is
"available" in all countries and using that it is possible to go
through the following hoops:

  1) Select product "No product"  [ Submit ]
  2) Select the country you are interested in [Submit]
  3) Select the product you are interested in [Submit]

To end up with the desired country and product combination. So - all
in all I conclude that things can not be totally messed up?

Any tips or thoughts on this would be great!

Joakim





-- 
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: Form with two select boxes + javascript - selection gets destroyed???

2011-04-15 Thread Joakim Hove
Thank you for answering:

On Apr 15, 8:47 pm, Shawn Milochik  wrote:
> Two things:
>
>     1. Does your form use a prefix?

I don't really what you mean with prefix?
>
>     2. Please post a relevant excerpt of your request.POST data.


(I mangled things a bit up in the original message; in particular the
offending field is not named product_id but rather agent_id):

This is my POST data:

   Variable Value
   name u'Bjarne Grethe'
   org_id   u'-1'
   country_id   u'45'
   telephoneu'78'
   agent_id u'43'  <--- This is the relevant quantity
   .

And this is the results of pressing "Local vars" in the traceback in
from clean():

   ▼ Local vars VariableValue
   country  
   self 
   country_id   45
   org_id   -1
  agent_id  None < Now it has become None???


Joakim

-- 
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: Form with two select boxes + javascript - selection gets destroyed???

2011-04-15 Thread Joakim Hove
Thank you to everyone answering - I will look into the Firebug
approach the next time. But now I am 99.9% certain that

> In an item is not in the original choices then it's invalid.

This is the problem. In the cases where things failed the choice
eventually sent from the client was not in the initial set. Thanks a
lot!

Joakim

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



{{ STATIC_URL }} and RequestContext()

2011-04-25 Thread Joakim Hove
Hello,

I have just started using the {{ STATIC_URL }} template tag to insert
proper url's to static resources in my templates. To use this tag I
need to create the context for rendering as RequestContext() instance,
which takes the request as a parameter for the initialisation.

In my code I have several methods attached to models which create a
suitable context for rendering that model instance in a specfied way:

class MyModel( models.Model ):



def create_xxx_context( self , **kwargs):
 

def create_yyy_context( self, ,**kwargs):
 

(Maybe that is a horrific design in the first place ???).


Anyway - the methods create_???_context() do not have natural access
to the request object (and I am reluctant to pass that argument on) -
so I was wondering if I could achieve exactly the same by just
"manually" adding the context variable STATIC_URL like:

from django.conf import settings


def view(request, args):
context = .
context["STATIC_URL"] = settings.STATIC_URL
return render_to_response( template , context )

Or is there more magic to the {{ STATIC_URL }} tag when it comes as a
RequestContext()?


Joakim

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



Implement su (i.e. substitute user) in Django

2011-05-23 Thread Joakim Hove
Hello,

for my little site there are a couple of different types of users, and
the view presented to the user differs depending on what type of user
this is. For me (as a super user) - it would be very convenient If I
could change identity and become another user, without having to log
out and log in again. My super-naive first attempt was just like this:


def su_view( request ):
  new_user = User.objects.get( pk = 10 )   # Hardcoded id = 10
  request.user = new_user
  return HttpResonpseRedirect("/")

But that did not work (not very surprising ...). Is what I try do at
all possible? Any hints on how to achieve this?

Regards Joakim

-- 
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: Implement su (i.e. substitute user) in Django

2011-05-23 Thread Joakim Hove
Hmmm;

thank you for answering.

> from django.contrib.auth import login
>
> (in view)
> login(request, user)

This was indeed simple; however I can unfortunately not get it to
work. The view returns a traceback starting with:

AttributeError at /su/
'User' object has no attribute 'backend'


Any idea?

Joakim

-- 
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: Implement su (i.e. substitute user) in Django

2011-05-23 Thread Joakim Hove

> Before the login call:
>
> user.backend = 'django.contrib.auth.backends.ModelBackend'

Works like charm; thank you very much!

Joakim

[PS: For others reading this - the right hand side in the assignment
above should indeed be a string literal, i.e. with the '']

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



Authorization of static content

2011-02-23 Thread Joakim Hove
Hello,

I am using Django to create an album application. I was planning to
use djangos user system for authorization, however the final image
viewing will be like:

 

Where image.url should resolve to something like 
http://static-images.com/path/to/image.jpg

Here http://static-images.com is another apache virtual host which
only serves static content. However this scheme fails miserably when
it comes to authorization - anyone can completely bypass my django app
(with authorization) and point their browser to:

http://static-images.com/path/to/image.jpg

Any suggestions of how to combine django based authorization with
serving of static content? I am the owner of the box in question and
can modify the apache setup way beyond my competence.

Regards - Joakim Hove

-- 
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: Authorization of static content

2011-02-23 Thread Joakim Hove
Thank you;

that was a very good starting point - I will hopefully find a solution
from this.

Joakim

On 23 Feb, 09:18, Mike Ramirez  wrote:
> On Wednesday, February 23, 2011 12:03:12 am Joakim Hove wrote:
>
> > Hello,
> > Any suggestions of how to combine django based authorization with
> > serving of static content? I am the owner of the box in question and
> > can modify the apache setup way beyond my competence.
>
> > Regards - Joakim Hove
>
> You might want to look into this[1] for the http basic authentication.  I
> personally haven't used http basic auth with django, yet.  But the page looks
> to be a good starting pont.
>
> Mike
>
> [1]http://stackoverflow.com/questions/152248/can-i-use-http-basic-
> authentication-with-django
> --
> My opinions may have changed, but not the fact that I am right.

-- 
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: Use 3rd party django package in my own project (PYTHONPATH)

2015-05-12 Thread Joakim Hove
,

> Thanks for the reply. My problem is with this section. can you guide me
> how to do this part in Ubuntu or Windows?
>
>
>-
>
>Add the model_report directory to your Python path.
>
>
Well - the main point is not adding the model_report directory to your
Python path per se - the point is that your python interpreter should find
the model_report package. To test that you can run Python interactively and
try to import the model_report package:

python
>> import model_report

If that works (which it should when you have installed with pip install)
you are good to go, otherwise you need to update the PYTHONPATH environment
variable. Exactly how to set the PYTHONPATH variable depends on your
OS/Shell - but for instance with Ubuntu and bash it would be:

export PYTHONPATH=/path/to/your/python/stuff

J

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M_6NY50Q%2ByvC%2BX9oMXd3Y4YJHRCDEXeNjfCtSuOb3%3DEdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


FileField - not stored to disk when using mod_wsgi?

2017-11-27 Thread Joakim Hove
 I ave django file upload application. I have a model looking like this:

class BaseFile(Model):
input_name = CharField( max_length = 132 )
content = FileField( upload_to = "%Y/%m/%d" )
upload_time = DateTimeField( auto_now_add=True )
owner_group = CharField( max_length = 32 , default = None )


In the settings.py file I have set:


MEDIA_ROOT = "/tmp/storage"


When I use this with the development server things seem to work, I can 
upload files and if I go to the /tmp/storage directory I can see the 
%Y/%m/%d directories created and populated with my files.

When I try this using Apache and mod_wsgi things also seem to work:

   1. The HTTP POST returns status 200.
   2. A subsequent GET will return the files in question.

But - when I go the /tmp/storage directory there are no directories/files 
to be found and if I stop and start Apache the GET will fail with:


IOError: No such file: /tmp/storage/2017/11/27/FILEX_Z1OZMf8 


So - it seems to me that Django keeps the files in memory when using 
mod_wsgi? I am using 100% default Django settings when it comes to storage 
backend. I see no errors in the Apache log.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ed264e4-144f-4943-aa28-a155da21366c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FileField - not stored to disk when using mod_wsgi?

2017-11-28 Thread Joakim Hove
> I suspect this might be due to permissions, because on linux, /tmp is
> owned by root and the apache service runs as user apache.
>

I agree that this has a certain smell of permissions, but I have at least
tried to rule that out. In particular I have:


   1. I have created the directory /tmp/storage manually beforehand - and
   applied "chmod a+rwx /tmp/storage"
   2. When I intentionally limit the permissions so that user 'apache' can
   not write in this directory I immediately get a "OSError . permssion
   denied" when uploading files.
   3. I can not see anything in the apache error_log.


Can you confirm that you're using mod_wsgi_py3 for python3 and not regular
> mod_wsgi, which is for python2 only.
>


Ehhh - I am using Python2.7 and can confirm that I am using regular
mod_wsgi.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M-VZpa6LKB30xSgybXT9xdx2Q3gGmXPiz1VYT-xLYMg4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: FileField - not stored to disk when using mod_wsgi?

2017-11-28 Thread Joakim Hove
> What's your view that's responsible for handling that model instanciation?
>

This of course quickly gets slightly unwieldy - but thanks for the
interest. The view/endpoint accepting the POST is this:

https://github.com/joakim-hove/fmu_storage/blob/master/ensemble/api/views.py#L56

The relevant function call is the `Simulation.upload( )` call on line 74;
and that is implemeted here:
https://github.com/joakim-hove/fmu_storage/blob/master/simulation/api/views.py#L107
(observe that there is a 'import as ' which enforces a class rename). The
full model module is here:
https://github.com/joakim-hove/fmu_storage/blob/master/simulation/models.py

Regards - Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M97vZW6Su%2BSpeX_kHktFFN598sSW9x%3DBRmuFUAVm-mU%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: FileField - not stored to disk when using mod_wsgi?

2017-11-28 Thread Joakim Hove
> /tmp is for temporary files, and its very possible Apache is cleaning up
> those files created through its process when you terminate the server.
>

I agree that could have been the case - but do observe that I can not see
any files/directories when Apache is running either.



> I would create a different folder path and use that.
>
>

OK - I have created a new directory `/data/storage` and set `MEDIA_ROOT` to
point there. Results are the same.

I was wondering if there was some explicit way to force writing to files?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M9Mh_Dtxy%3Dkppbm9%3DzxLR38BfEPONPNr%2B9B5CY9ryH6Hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Joakim Hove
Sounds to me that what you want is a `singleton` implemented in Python .
The fact that Django is involved does not seem to be very relevant?


8. jan. 2018 22:43 skrev "Kasper Laudrup" :

> Hi Antonis,
>
> On 2018-01-08 22:10, Antonis Christofides wrote:
>
>> Hello,
>>
>> When you say "call [an instance of an object]", what exactly do you mean?
>>
>>
> Sorry, I meant an instance of a class or just an object.
>
> Could you tell us more about what this class/object is and why you need to
>> "call" (access?) it in an unusual way?
>>
>>
> Nothing unusual about the class or object, sorry about the confusion.
>
> My question is probably fairly simple and I'm really sorry if there's
> something very basic that I'm missing.
>
> I want to create an instance of some class when the Django application I'm
> creating is ready (eg. by connecting to the ready() signal or similar) and
> then be able to call methods on that single instance from my models.
>
> Thanks a lot for the help so far.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/bd87c994-77da-529b-1416-2e6d7a8d2aa5%40stacktrace.dk.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8O8SLtfJK5cwj86x3Aad7T_45KdQAxMAYuUxSbfsEY0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Migration failing?

2017-01-09 Thread Joakim Hove
Hello;

I have a long running Django project; it started on version ~1.0. I have 
upgraded regularly and I am now on 1.10. I have been using migrations with 
Django since the became standard (1.8??) and generally been very happy with 
them. However today I am facing a problem with a migration which I have not 
been able to solve.

Initially I have a model Organisation:

class Organisation( Model ):

   field1 = ... DB_COLUMN = "FIELD1")
   field2 = ... DB_COLUMN = "FIELD2")


   class Meta:
  db_table = "ORGANISATIONS"


Observe that I have used the 'DB_COLUMN' and 'db_table' attributes to give 
non-standard names to columns and tables. The database was retrofitted to 
use Django, this is a relic from that conversion. Then today I added a 
small new 'model' for organisation type:


  class OrganisationType( Modell );
id = ...
description = ...


Using makemigrations I first added a migration to create the 
OrganisationType model, and then subsequently I added empty/data migration 
to create one instance of the OrganisationType model. I then added a new 
ForeignKey on the Organisation model:


  class Organisation( Model ):

org_type = ForeignKey( OrganisationType ,db_column = 
"ORGANISATION_TYPE")

Now when I try makemigrations it fails. The end of the traceback is:

django.db.utils.ProgrammingError: column ORGANISATIONS.ORGANISATION_TYPE 
does not exist
LINE 1: ...ES_UPDATED_BY", "ORGANISATIONS"."PRICES_UPDATED", "ORGANISAT...


So - it seems to be complaining that the 'ORGANISATION_TYPE' column is 
missing from the ORGANISATIONS table; now that makes sense - this was 
exactly the change I wanted a migration for! If I try other manage commands 
like `manage.py runserver` or `manage.py test` I get the same error. 

Any hints?

Joakim
 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/50eb2679-5d39-4175-9368-3ff08996b337%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migration failing?

2017-01-09 Thread Joakim Hove
An update: I think this was the clue:

If I try other manage commands like `manage.py runserver` or `manage.py 
test` I get the same error.


There was some code going through all Organisation objects during import - 
and that fails. Got to refactor a bit.
 



On Monday, January 9, 2017 at 11:32:24 PM UTC+1, Joakim Hove wrote:
>
> Hello;
>
> I have a long running Django project; it started on version ~1.0. I have 
> upgraded regularly and I am now on 1.10. I have been using migrations with 
> Django since the became standard (1.8??) and generally been very happy with 
> them. However today I am facing a problem with a migration which I have not 
> been able to solve.
>
> Initially I have a model Organisation:
>
> class Organisation( Model ):
>
>field1 = ... DB_COLUMN = "FIELD1")
>field2 = ... DB_COLUMN = "FIELD2")
>
>
>class Meta:
>   db_table = "ORGANISATIONS"
>
>
> Observe that I have used the 'DB_COLUMN' and 'db_table' attributes to give 
> non-standard names to columns and tables. The database was retrofitted to 
> use Django, this is a relic from that conversion. Then today I added a 
> small new 'model' for organisation type:
>
>
>   class OrganisationType( Modell );
> id = ...
> description = ...
>
>
> Using makemigrations I first added a migration to create the 
> OrganisationType model, and then subsequently I added empty/data migration 
> to create one instance of the OrganisationType model. I then added a new 
> ForeignKey on the Organisation model:
>
>
>   class Organisation( Model ):
> 
> org_type = ForeignKey( OrganisationType ,db_column = 
> "ORGANISATION_TYPE")
>
> Now when I try makemigrations it fails. The end of the traceback is:
>
> django.db.utils.ProgrammingError: column ORGANISATIONS.ORGANISATION_TYPE 
> does not exist
> LINE 1: ...ES_UPDATED_BY", "ORGANISATIONS"."PRICES_UPDATED", "ORGANISAT...
>
>
> So - it seems to be complaining that the 'ORGANISATION_TYPE' column is 
> missing from the ORGANISATIONS table; now that makes sense - this was 
> exactly the change I wanted a migration for! If I try other manage commands 
> like `manage.py runserver` or `manage.py test` I get the same error. 
>
> Any hints?
>
> Joakim
>  
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff1c8a6d-ec60-4e4e-ba60-a792991a1eaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Time tracker sytem

2019-02-03 Thread Joakim Hove
I have created such a system - it is extremely basic, but it covers my
needs. Feel free to take a look:

https://github.com/joakim-hove/ptime

Den søn. 3. feb. 2019, 15:26 skrev Rupam Hazra  I want to create a time tracker system to track the employee work time and
> data save to mysql database.please tell me how to start.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6e4c36c8-10ea-403d-9afa-8c9b40c1f1e6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6e4c36c8-10ea-403d-9afa-8c9b40c1f1e6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8PxoOW0BmL851RvLnL12BEuF8W2movQknf2KCi8La5Sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Time tracker sytem

2019-02-03 Thread Joakim Hove
A space sneaked in in the github address:

https://github.com/joakim-hove/ptime

Den søn. 3. feb. 2019, 15:50 skrev Joakim Hove  I have created such a system - it is extremely basic, but it covers my
> needs. Feel free to take a look:
>
> https://github.com/joakim-hove/ptime
>
> Den søn. 3. feb. 2019, 15:26 skrev Rupam Hazra 
>> I want to create a time tracker system to track the employee work time
>> and data save to mysql database.please tell me how to start.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/6e4c36c8-10ea-403d-9afa-8c9b40c1f1e6%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/6e4c36c8-10ea-403d-9afa-8c9b40c1f1e6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M-2ZtbJiT3d7mb3gVgAocZTt6jOavZxNZrkumQVjpZAPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Failed to push Django project on github using gitbash

2019-04-18 Thread Joakim Hove
> [...]  and merged also but it was giving same error again and again.

bash% git fetch origin  (assuming your remote is "origin" - which is
typically the default)
bash% git merge origin/master
bash% git push origin master

If this for some reason does not work (I can not understand why it should
not - but anyway) you can always force:

bash% git push -f origin master

The force (-f) will override the protection which is creating trouble for
you - but before doing that; be certain you want to overwrite what is on
the remote!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8tyreNccmg%3DP-xPfo%2BDX94Wmmunit69A%3DqmHFR%2BjR4AQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Add new primary key to model

2017-02-18 Thread Joakim Hove
Hello;

I have a model with a CharField which is used as primary key:

class MyModel( Model ):
 string_id = CharField("StringID" , primary_key = True )

I would now like to migrate this model to have a normal integer AutoField 
as primary key, and the string_id field should just be a unique string:


class MyModel( Model ):
   int_id = AutoField( primary_key = True )
   string_id = CharField( "StringID", unique = True )


I have tried several ways of doing this, but it either fails in the 
'makemigrations' step, or when I try to apply the migration. Any tips?

Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/338750fb-7b7c-444c-a920-50b018e2a3a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Heroku database migration

2020-07-19 Thread Joakim Hove
bash% heroku run python. /manage.py migrate

søn. 19. jul. 2020, 18:48 skrev Aman Mandloi :

> Added a small model 'new_model' in existing app 'existing_app' on Django,
> Entered commands manage.py makemigrations and manage.py migrate it
> migrated changes to local database.
> Tried to apply same on heroku but its not working there. I then tried to
> setup heroku database in local settings.py of project and migrations worked
> but it shown some well known error, I have attached the output with this
> discusssion. Attaching the final screenshot as output.
>
> _Just In Case if it may
> help___
> The following are the methods I have applied before the final solution:-
> 1. With heroku run manage.py makemigrations
> 2. Adding makemigrations command to procfile
> 3. Pushing migrations as well, so it may replace server migrations
> The all three mentioned steps provided this output:- "No migrations to
> apply, and on migrate it shows you dont have new migrations",
> helping out to migrate changes on database.
> Thank You.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ee20b599-619d-4b38-949d-fdfb18cf9711o%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8Aj_nKW5UVV7phGkDR1_dANRKPb3kRzg8B_ihhURXfaQ%40mail.gmail.com.


Best practice when designing an api (with Django)

2015-08-31 Thread Joakim Hove
Hello;

[ This question might be more about general principles for API design than
Django, but since Django is my tool of choice - and my context of
understanding, I am posting it here.]

I have been maintaining a small Django based website for some time. It is
mostly based on conventional views returning HTML, but both to support
JavaScript interactivity and to interact with a traditional desktop
application I am gradually creating a REST based API. Up until now I have
created the REST endpoints manually, but I now I intend to look into the
Django Rest Framework (DRF) and try to do things more properly. Now - the
question where I would appreciate some guidance boils down to: "How much
should I use my own http based API internally?". Assume I have two django
models 'Author' and 'Book', each book can have several authors and of
course each author can write several books - i.e. this is a many to many
relationship:

class Author(models.Model):
 
 books = models.ManyToManyfield( "Book", ...)

class Book(models.Model):
 

It is then natural(?) to configure the urls:

/books/1   - Get information about the book with ID=1
/authors/7- Get information about the author with ID=7

But let us say that I wanted to create the endpoint:

/books/7/authors

To get the author information for the authors of the book with ID=7. In my
view I have used:

book = Book.objects.get( pk = 7 )

To get the right book, now I want the author details. As I see it I have
two approaches to get the author details:


   1. I can just use the ordinary Model/ORM methods.
   2. I can use my own http api - and "loopback" repeated calls to:
   /authors/$ID

On the one hand I strongly believe in the "eat your own dogfood" principle,
but on the other hand it feels a bit over the top to issue http calls in
this situation? Grateful for comments from experienced API desginers.


Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M-SQY9JV6vgH_QgqMW6BLh6EAPbTT7KokcQvka8gzp7uQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice when designing an api (with Django)

2015-08-31 Thread Joakim Hove
Thank you for an informative answer ;-)



> > To get the author information for the authors of the book with ID=7. In
> my
> > view I have used:
> >
> > book = Book.objects.get( pk = 7 )
>
> Where exactly did you use this? Can you post up a copy of the view?
>

This was currently only a construction in my head; and not literally from
an existing view. You have answered the question firmly further down.


> > [...] ust use the ordinary Model/ORM methods.
>
> ^^^ This one. ^^^


Clear answer!




>
> You can use repeated calls, but at that point you are trying to eat
> your own dog food using a straw.
>

Well - that does not sound terribly efficient.


> Have you gone through the DRF tutorial?


I'm in the process - very pleasent documentation by the way.


Thank's again - Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M9Kjo_fNf9T%2B71_so1Z7QWE%3D7VP-4anEHFN%3DTU1drShxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Locking / serializing access to one element in database

2015-10-21 Thread Joakim Hove
Hello;

this arises in the context of a django application  - but it might be a 
more general Python/Postgres/... problem.

[ The django application is existing all right - but the problem I am 
describing here is yet only in my head; I am seeking advice on how to 
proceed. ] Assume I have a model with a large text field:


class TextModel(models.Model):
 text = models.TextField( ... )

 @classmethod
 def update(cls, id , new_text):
   # Fetch existing ID - or alternatively create a new one.
   try: 
   tm = TextModel.objects.get( pk = id )
   except TextModel.DoesNotExist:
   tm = TextModel( )

   # Perform time consuming calculation (strcat just for 
demonstration) and save again.
   tm.text += new_text   
   tm.save()


Now - obviously the whole update() method is one big screaming 
race-condition, but it is not clear to ensure that only one thread/process 
is accessing this DB element at a time. Suggestions on how to solve this 
race condition - or suggestions of an alternative race free approach would 
be highly appreciated.


Joakim


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58e4726a-898c-4ef2-a49a-fd9d43552d99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking / serializing access to one element in database

2015-10-22 Thread Joakim Hove
Thank you;

> I would suggest you use select_for_update() 
 
in 
a transaction.

That seems to be just what I want!


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a863746b-8b38-496f-ad65-12948cab6e8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking / serializing access to one element in database

2015-10-24 Thread Joakim Hove

>
>
> This only covers the case where the object with the given ID already 
> exists, doesn't it? 
>

Yes - it must be so; thank you for pointing out. In my particular case I 
can get around it be pre creating an empty element, but that is not very 
nice - I will look at Collins suggestion. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db0a7d08-a75b-4d53-aa5a-ad6422b53a46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking / serializing access to one element in database

2015-10-24 Thread Joakim Hove
Hi Collin;

thank you for your suggestion:

[...] if the thread thinks that the object is new, it could try using 
> .save(force_insert=True). 
>

I have read to read the force_insert documentation without understanding 
100%. Assume threads t1 and t2 are racing to create the first element with 
this primary key, and that t1 wins the race. Then when t2 issues:

save( force_insert = True )

will an exception be raised?

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b950b775-4f57-41b1-a96f-472b3e064e8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Postgis - as an afterthought?

2015-10-25 Thread Joakim Hove
Hello, I have started developing a Django application. Currently it is not 
ready for it, but in the future I see that I would probably like to use the 
GeoDjango application/extension. Will I be able to add that a later stage, or 
do I need to design the application for that from the start?

I am using Postgres on Heroku currently.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0bc6e82a-7a33-4cb1-af73-958179212928%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Postgis - as an afterthought?

2015-10-25 Thread Joakim Hove
Thank you!
25. okt. 2015 22:17 skrev "Thomas Lockhart" 
følgende:

> On 10/25/15 11:20 AM, Joakim Hove wrote:
>
>> Hello, I have started developing a Django application. Currently it is
>> not ready for it, but in the future I see that I would probably like to use
>> the GeoDjango application/extension. Will I be able to add that a later
>> stage, or do I need to design the application for that from the start?
>>
>> I am using Postgres on Heroku currently.
>>
>> You can add it in anytime. In older versions of Django you may need to do
> minor changes if you add geo fields to existing apps.
>
> hth
>
> - Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/562D46EA.2050600%40gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M9oZoqaXi%3DydwO9aLccjbhLyv57xGWM%2BhKwTG7EJ7ommA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Time out when requesting element from Admin

2015-11-13 Thread Joakim Hove
[ I realize what I am trying to do might be a prime example of abusing the 
admin. The real answer to my question might very well be: 'sorry - the 
admin is just not made for that', and that is fine. The main reason I am 
asking this is to learn more myself - and most importantly to rule out 
other problems in my setup ]


Hello;

I have a model with ~20 records and growing (is that "much"?). I can 
visit the /admin/app/model/ url in the Admin and get a listing of all the 
records/instances - but when I click on one of the actual instance - i.e. 
something /admin/app/model/12345/ the application times out (30 seconds on 
Heroku). The model in question is quite simple:

model A:
foreignKey( B )
foreignkey( C )
float( )

model B
foreignkey( D )
foreignkey( D )
foreignkey( E )

The relationship between A and B is 'nearly' one-to-one; i.e. there are 
roughly as many rows of A as there rows of B (The B model is currently not 
in the admin). For the other model C.D,E,.. the relationship is extremely 
'many-to-few' - i.e. the database only contains a handful of C,D,E, 
instances. I was wondering if something like prefetching foreign keys??? 
brought the whole thing to its knees?


The site is actually mainly an API - and the model in question is also 
exposed through a Django Rest Framework (DRF) endpoint:

List view - times out: https://friskby.herokuapp.com/sensor/api/datavalue/

One element - OK: https://friskby.herokuapp.com/sensor/api/datavalue/1/


So - for the DRF configuration the situation is actually opposite; 
accessing the whole list times out (I have not done anything to configure 
pagination - so this might be OK?); whereas fetching one element is snappy. 
The admin site is password protected - but it only contains test-data and I 
would be happy provide login details if someone want's to take a look.

If someone can shed some light on this I would be very grateful.

Joakim


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4c31c348-4207-4afa-916b-2df79decff09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Time out when requesting element from Admin

2015-11-15 Thread Joakim Hove

>
>
> By default, Django’s admin uses a select-box interface () for 
> fields that are ForeignKey. Sometimes you don’t want to incur the 
> overhead of having to select all the related instances to display in the 
> drop-down.
>

Thanks a lot - that was what it was all about; Django tried to populate a 
 box O(1) elements - fair enough that that timed out. I just 
removed the foreignkey in question from the AdminModel!

Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/abad93f4-f72c-4b49-9f8b-ce8b8267b97d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Custmo field numpyarray - why does this even work?

2015-12-02 Thread Joakim Hove
Hello;

I want to create a custom model field for storing a numpy array. It has 
currently been so simple that I fear I am overrlooking something and 
getting a very false positive?


class NumpyArrayField(BinaryField):
dtype = numpy.float32

@classmethod
def load_numpy_array(cls , blob):
return numpy.fromstring(blob , NumpyArrayField.dtype)

def __init__(self , *args , **kwargs):
kwargs['default'] = None
super(NumpyArrayField , self).__init__(*args , **kwargs)


def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return self.load_numpy_array( value )


def to_python(self, value):
if isinstance(value, numpy.ndarray):
return value

if value is None:
return value

return self.load_numpy_array( value )


As I see it this has (essenially two versions) of code for deserializing 
from a database value to a numpy array, but no method for the opposite 
operation. However it seemingly works?

I have created a small model with one of these fields:



class TimeSeries(Model):
start = DateTimeField( )
step = IntegerField( )
data = NumpyArrayField( )


@classmethod
def createArray(cls , size = 0):
return numpy.ndarray( shape = [size] , dtype = 
NumpyArrayField.dtype)

def __getitem__(self , index):
if self.data is None:
raise IndexError
else:
return self.data[index]

def __setitem__(self , index , value):
if self.data is None:
raise IndexError
else:
self.data[index] = value


def __len__(self):
if self.data is None:
return 0
else:
shape = self.data.shape
return shape[0]



And a test:


class TimeSeriesTest(TestCase):

def test_create(self):
ts = TimeSeries.objects.create( start = timezone.now(),
step = 100 ,
data = TimeSeries.createArray( ))
self.assertEqual( len(ts) , 0 )
with self.assertRaises(IndexError):
ts[0]

ts.addValue( 1 )

self.assertEqual( len(ts) , 1 )
with self.assertRaises(IndexError):
ts[1]

self.assertEqual( ts[0] , 1 )
 
# How on earth does the NumpyArrayField know how to save itself to 
the db?
ts.save()

ts2 = TimeSeries.objects.get( pk = 1 )
self.assertEqual( ts2[0] , 1)
self.assertEqual( len(ts2) , 1 )


I was expecting the test to fail spectacularly when calling ts.save() - 
however it seems to work, and I can even get the instance back from db - 
what gives?  I am using sqlite and have tried to force the db to create a 
file.

I was excpecting to implement the get_prep_db_value() method - but now when 
things seemingly work without it I get quite uncertain? Is there some magic 
trickery involved which says that this should indeed work - or am I seeing 
a completely false positive?

Joakim





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09fa67a5-70b6-40c4-a600-13ea9cbbd97c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custmo field numpyarray - why does this even work?

2015-12-02 Thread Joakim Hove
Sorry;

how do you get the nice code formatting - I thought it was through the use 
of   ...  blocks?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e70d787-3484-43e0-9414-e7252113de69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Hello,

I have a model `Transaction` which can be viewed at the url: 
/transaction/view/$ID/ - if I just enter that url in the browser, or in 
template everything works. But when I have the following get_abolute_url() 
method:

def get_absolute_url(self):
 return "/transaction/view/{}/".format( self.id )

things do not work from the Admin. When I click on the "View on Site" link 
i am redirected to "http://example.com/transaction/view/23635/"; and I get 
an error message about failed XML parsing. I have no clue where the 
"example.com" address comes from - that string is not in my codebase. If I 
hardcode the get_absolute_url to:

def get_absolute_url(self):
 return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)

That works in development, but needless to say that is not a very good 
approach.

I am on Django 1.10


Regard Joakim


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6e8b55d-56b5-40f4-8505-76f1447c1542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Thank  you for answering;

but I do not agree fully with your answer:

1. It is the @permalink decorator which is removed from Django 2.x - not
the get_abolute_url() method.
2. I agree using the reverse in the get_absolute_url() is nicer, and I have
also tried that - but the ersults were the same ... ;-(
3. Yes - I should upgrade

On Sun, Jun 10, 2018 at 2:19 PM Gerald Brown  wrote:

>  In version 2 of Django that function has been removed.
>
> For v 1.10 here is a link that might help:
> https://docs.djangoproject.com/en/1.10/ref/models/instances/#get-absolute-url
>
> Here is another link that might be of help:
> https://stackoverflow.com/questions/13503645/what-is-permalink-and-get-absolute-url-in-django?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
>
> Hope this helps.
>
> BTW the first link says V1.10 is obsolete and is no longer supported!!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1c0b4b32-7154-4dd4-b437-92d0bba6c70e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8HqPs9rijWh63bAThh-o-6EsLNYFWLGQBm4%2BXjqkbB2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove

>
>   
>
> > It is the default hostname for django.contrib.sites 
> 
>  
> with SITE_ID = 1.
>
>
OK - so that might be a smoking gun that I have not configured the "sites" 
model correctly? I have so far not really related to the "sites" 
functionality at all. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dee9819f-fb1d-4a2f-9449-89ec0b3a8370%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Thank you;

that was indeed it!

On Sunday, June 10, 2018 at 11:03:54 PM UTC+2, Melvyn Sopacua wrote:
>
> On zondag 10 juni 2018 22:54:10 CEST Joakim Hove wrote: 
> > > > It is the default hostname for django.contrib.sites 
> > > 
> > > <
> https://github.com/django/django/blob/master/django/contrib/sites/managem 
> > > ent.py#L28> with SITE_ID = 1. 
> > 
> > OK - so that might be a smoking gun that I have not configured the 
> "sites" 
> > model correctly? I have so far not really related to the "sites" 
> > functionality at all. 
>
> It's enabled by default. And from the admin you can edit that hostname and 
> add 
> more sites. 
> Because Django supports multiple sites with a single admin, it generates 
> fully 
> qualified URLs for the "view on site" functionality, if 
> django.contrib.sites is 
> in INSTALLED_APPS. 
>
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/af654af4-ff87-45bd-9da4-038cbefc09cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-11 Thread Joakim Hove
Thank you;

my main problem was with the sites model - and the default value for
SITE_ID == 1. I had no intention of hardcoding the URL.

On Mon, Jun 11, 2018 at 12:58 AM Anthony Anonde  wrote:

> the example.com is am example django give for Site. Which means there is
> a way for you to manage more than one site at a time, basically using the
> site_id.
> To you Questions, i don't understand why you want to hard code your uri
> routing like that when you can easily use the app_name and name convention
> which is more dynamic then hard coding it like that:
> for example at the model Transaction urls.py
> app_name = "trans"
> url(r'(?P-/d+)$', views.func, name='account_trans'),
>
> def get_absolute_url(self):
> return reverse("trans:account_trans",  kwargs={"pk":self.pk})
>
>
> and you will be just fine hope this help
>
>
>
> On Sunday, June 10, 2018 at 12:30:51 PM UTC+1, Joakim Hove wrote:
>>
>> Hello,
>>
>> I have a model `Transaction` which can be viewed at the url:
>> /transaction/view/$ID/ - if I just enter that url in the browser, or in
>> template everything works. But when I have the following get_abolute_url()
>> method:
>>
>> def get_absolute_url(self):
>>  return "/transaction/view/{}/".format( self.id )
>>
>> things do not work from the Admin. When I click on the "View on Site"
>> link i am redirected to "http://example.com/transaction/view/23635/"; and
>> I get an error message about failed XML parsing. I have no clue where the "
>> example.com" address comes from - that string is not in my codebase. If
>> I hardcode the get_absolute_url to:
>>
>> def get_absolute_url(self):
>>  return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)
>>
>> That works in development, but needless to say that is not a very good
>> approach.
>>
>> I am on Django 1.10
>>
>>
>> Regard Joakim
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5678b297-2693-4ae8-b249-08e42713ebf7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5678b297-2693-4ae8-b249-08e42713ebf7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M_diEj6K9Mw7kPAvrjWs6JUjE1H0-zgB-0M8VFKSDVq%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem with Postgresql-11.9 ??

2020-10-12 Thread Joakim Hove
[ This question is also posted to StackOverflow:
https://stackoverflow.com/questions/64320386/django-postgresql-model-with-only-foreign-keys
]

I have a model which looks like this:

class InputTypeMap(models.Model):
input_type = models.ForeignKey(InputType, on_delete=models.CASCADE)
training = models.ForeignKey(Training, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
gender = models.ForeignKey(Gender, on_delete=models.CASCADE)

When I try to create instances of this model with:

InputTypeMap.objects.create(input_type=input_type,
training=training,
gender=gender,
category=category)

I get an exception when using Postgres-11.9:

Traceback (most recent call last):
  File 
"/home/hove/sleipner/venv/lib/python3.7/site-packages/django/db/backends/utils.py",
line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.NotNullViolation: null value in column "id" violates
not-null constraint
DETAIL:  Failing row contains (null, Maintenance, Female, MareGielding, No).

>From the error message it seems to me that a ID key for the new entry is
not generated. This code has worked as I expected for quite some time, but
has "suddenly" started to fail locally - probably after a apt get upgrade.
When I run the same code with sqlite or Postgres-10.14 thing continue to
work as before. It is not clear to me whether this is a bug in my code
(most probable ...), Django or Postgres. I am using Django version 3.1.2

Any hints appreciated.

Regards - Joakim Hove

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M-YbR80USkq%2BLLyWHR7iem66ALcc9bH6dYGOEP9ywWkfA%40mail.gmail.com.


Re: Problem with Postgresql-11.9 ??

2020-10-12 Thread Joakim Hove
Thank you for answering. Just to be sure: you agree that the behavior I
describe looks like a bug somewhere?

man. 12. okt. 2020, 23:42 skrev Thomas Lockhart :

> No one has answered yet, so here is some useless info…
>
> I’ve been using various combinations of Postgres and Django (currently
> 12.4 and 3.1.2, respectively) and would think I would have stumbled on this
> at some point when using postgresql-11. But I probably haven’t tried 11.x
> with 3.1.2 specifically…
>
> - Tom
>
> On Oct 12, 2020, at 9:24 AM, Joakim Hove  wrote:
>
> [ This question is also posted to StackOverflow:
> https://stackoverflow.com/questions/64320386/django-postgresql-model-with-only-foreign-keys
> ]
>
> I have a model which looks like this:
>
> class InputTypeMap(models.Model):
> input_type = models.ForeignKey(InputType, on_delete=models.CASCADE)
> training = models.ForeignKey(Training, on_delete=models.CASCADE)
> category = models.ForeignKey(Category, on_delete=models.CASCADE)
> gender = models.ForeignKey(Gender, on_delete=models.CASCADE)
>
> When I try to create instances of this model with:
>
> InputTypeMap.objects.create(input_type=input_type,
> training=training,
> gender=gender,
> category=category)
>
> I get an exception when using Postgres-11.9:
>
> Traceback (most recent call last):
>   File 
> "/home/hove/sleipner/venv/lib/python3.7/site-packages/django/db/backends/utils.py",
>  line 84, in _execute
> return self.cursor.execute(sql, params)
> psycopg2.errors.NotNullViolation: null value in column "id" violates not-null 
> constraint
> DETAIL:  Failing row contains (null, Maintenance, Female, MareGielding, No).
>
> From the error message it seems to me that a ID key for the new entry is
> not generated. This code has worked as I expected for quite some time, but
> has "suddenly" started to fail locally - probably after a apt get upgrade.
> When I run the same code with sqlite or Postgres-10.14 thing continue to
> work as before. It is not clear to me whether this is a bug in my code
> (most probable ...), Django or Postgres. I am using Django version 3.1.2
>
> Any hints appreciated.
>
> Regards - Joakim Hove
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALKD1M-YbR80USkq%2BLLyWHR7iem66ALcc9bH6dYGOEP9ywWkfA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALKD1M-YbR80USkq%2BLLyWHR7iem66ALcc9bH6dYGOEP9ywWkfA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1C816206-3EC7-4696-806E-FD810E76C251%40gmail.com
> <https://groups.google.com/d/msgid/django-users/1C816206-3EC7-4696-806E-FD810E76C251%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8O4%3DtQ%2BxuEE7%2BzC17%2BjnotzUzEDU3EkoqVTPDOTngQMg%40mail.gmail.com.


Does not automatically assign ID?

2020-10-14 Thread Joakim Hove
Disclaimers:

   1. This issue is also on StackOverflow:
   
https://stackoverflow.com/questions/64320386/django-postgresql-model-with-only-foreign-keys
   2. I posted this here in this group a couple of days ago without finding
   a solution.

I must admit I am quite baffled by this problem, seems like a thing I have
done for years suddenly does not work any longer?? In particular the code
in question here has worked for a couple of months, and then "suddenly"
stopped working - probably due to "apt get upgrade", but I can not pinpoint
exactly when it stopped working. I post it again here with some corrections
and a bit more detail. Hopefully someone can see what I do wrong; if
someone wants to contact me off-list and offer commercial help I could be
interested in that.


I have a model which looks like this:

class InputTypeMap(models.Model):
input_type = models.ForeignKey(InputType, on_delete=models.CASCADE)
training = models.ForeignKey(Training, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
gender = models.ForeignKey(Gender, on_delete=models.CASCADE)

I.e. there are four fields in the model which are all foreign keys to other
models. The primary key is not added explicitly by me, rather I trust
Django to add the required primary key with an "invisible" AutoField. When
I create a new instance of this class like:

InputTypeMap.objects.create(input_type=input_type,
training=training,
gender=gender,
category=category)

I get an exception:

Traceback (most recent call last):
  File 
"/home/hove/sleipner/venv/lib/python3.7/site-packages/django/db/backends/utils.py",
line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.NotNullViolation: null value in column "id" violates
not-null constraint
DETAIL:  Failing row contains (null, Maintenance, Female, MareGielding, No).

>From the error message it seems to me that a ID key for the new entry is
not generated; I was expecting postgres to do that itself? When the same
code is run as a test on sqlite it works as intended.
Information about Postgres versions: Server 9.6 - Client 13

Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M-wcpm9PGMHXrE-jBaPDxMy3R3MuGiSvwASe0re97%2Bj9w%40mail.gmail.com.