Oracle GIS backend - no bulk_create?

2015-07-02 Thread Robert Martin
Hi all,

I've been trying to do a bulk_create using the Oracle GIS backend (Django 
1.8.2) and getting an AssertionError:

  File 
"C:\Users\robert.martin\Envs\ais\lib\site-packages\django\contrib\gis\db\backends\oracle\operations.py"
, line 248, in modify_insert_params
assert len(placeholders) == 1
AssertionError


In the code there's a comment: "This code doesn't work for bulk insert 
cases." Does anyone know of a workaround for this? I'm working with several 
large datasets and performance has been extremely slow.

Thanks for any advice!

-- 
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/58b25d95-a3ea-40f4-8853-48966a8cc71c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to Django to Scorm example turturial ?

2015-07-02 Thread Д . Энхбаяр
how to Django to Scorm example turturial ?

-- 
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/7374f00e-a081-413c-986e-14b748012e62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django formset hidden id field

2015-07-02 Thread Carl Meyer

On 06/28/2015 03:00 PM, Peter of the Norse wrote:
> On May 27, 2015, at 7:47 AM, Cheng Guo  > wrote:
>>
>> Hello,
>>
>> I have a formset and when I render it, Django would include this line
>> in the HTML:
>>
>> ||
>>
>> I am curious what is the purpose of having an id field here. 
>>
>> I mean in what situation would you use it. I did look through
>> Django's documentation on formset
>> but
>> cannot find much documentation on this.
>>
>> One answer I got is that this id field is the value of the primary key
>> of the model bound to this form. It is there so that when the formset
>> updates, people can use it to retrieve the corresponding record from
>> the database.
>>
>> Is the above explaination correct?
>>
>> If this explaination is correct, then my next question is, wouldn't it
>> be dangerous to expose the primary key like that? I can make a post
>> call to your server with a modified pk which can mess up your database.
> 
> So what?  It’s quite likely that whoever is editing this row of the
> database, also has permissions to edit the other rows as well.  There’s
> no reason for them to go through the hassle of manually editing a hidden
> field when they can go to a different page and edit it there.

That's a bad answer. It's common in many systems for a user to have
access to edit some records in a table but not others (this is often
known as "object-level permissions"). If it was really possible to edit
any row in the table by just manually editing the PK hidden field, that
would be a serious security flaw in formsets.

But it's not. Whatever queryset you pass to the model formset limits the
available rows for editing. The end user can edit the PK to refer to any
item in that queryset, but not any item in the table.

> In general, primary keys are not security flaws.  While it’s a good idea
> to hide them from front-end pages, that’s mostly because they make URLs
> hard to read.  I have heard that you don’t want to use them publicly,
> because your competitors can use them to gauge your success, but that’s
> the kind of “Nice Problem to Have” that can wait until you’re bigger.

Exposing primary keys themselves (e.g. in URLs) is not necessarily a
security flaw. Exposing a primary key in a hidden field that can be
edited to change a form to edit any row in a table often would be a
serious security flaw.


Carl

-- 
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/5595E969.1090205%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Django model for non web applications

2015-07-02 Thread Carl Meyer
On 07/02/2015 05:49 PM, Russell Keith-Magee wrote:
> 
> On Thu, Jul 2, 2015 at 12:50 AM, Jeff Fritz  > wrote:
> 
> I'm fairly new to Django and making my way through the tutorial.
> 
> Knowing what I've learned so far, I'd like to explore using
> django.db.models.Model in a non-web application. I'd like to take
> the entire model layer and use it for database access in a
> standalone, multithreaded python 3.4 application. It is not a web
> application. I would like to be able to take advantage of the
> migration capabilities in manage.py.
> 
> Questions:
> 
> 1. Is it as simple as adding `from djanago.db import models`? Would
> this bring in any unnecessary django packages/modules, considering I
> will not be developing a web application, not using views,
> templating, etc?
> 
> 
> It's *almost* this simple - you will also need to configure your Django
> environment before you start making database calls. If you're looking to
> do this in a *completely* "non-web" way, this probably means a call to
> settings.configure(); details here:
> 
> https://docs.djangoproject.com/en/1.8/topics/settings/

Don't forget that in Django 1.7+ you also need to call django.setup()
yourself, if using Django outside the context of a WSGI server or
management command:
https://docs.djangoproject.com/en/1.8/ref/applications/#django.setup

Carl

>  
> 
> 2. Is the django model layer thread safe? Specifically, when using
> sqlite3 as a back end?
> 
> 
> It should be - after all, web servers are frequently multi-threaded.
> SQLite3's performance under multithreading, however, might leave
> something to be desired.
>  
> 
> 3. Are there other clean ORM/database model layer
> frameworks/packages that I should consider for python 3.4?
> 
>  
> The other obvious candidate would be SQLAlchemy; it's a perfectly fine
> ORM - without any of the other web framework overhead. It's a lot more
> like a "SQL building toolkit" than Django's ORM - whether this is a good
> or bad thing depends on your own preferences and use case.
> 
> Yours,
> Russ Magee %-)

-- 
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/5595DC21.5060600%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Access dynamic session variable name in template

2015-07-02 Thread jorrit787
This doesn't seem to work :(

def comment_upvote(request, comment_id):
comment = get_object_or_404(Comment.objects.filter(id__exact=comment_id,
approved=True))
votes = request.session.setdefault('commentvotes', {})
if comment.id not in votes:
comment.upvotes = comment.upvotes + 1
comment.votes = comment.votes + 1
comment.save()
votes[comment.id] = True
else:
messages.error(request, 'You have already voted on this comment.')
return redirect('comments')

{% if comment.id not in 
request.session.commentvotes 
%}






{% endif %}

With this code the first time that someone loads the comments page (fresh 
session) no buttons show up at all (I guess because the session key is not 
set?). And it also doesn't prevent voting on the same comment twice.


On Thursday, July 2, 2015 at 8:41:48 PM UTC+2, Daniel Roseman wrote:
>
> On Thursday, 2 July 2015 19:09:59 UTC+1, jorr...@gmail.com wrote:
>>
>> Hi everyone,
>>
>> I am trying to keep track of who has voted on a comment by setting 
>> session variables like 'commentvote1', 'commentvote2', etc to True. These 
>> variable names are dynamically generated based on the id of the comment. 
>> How can I access these dynamic variables in my template? I've tried this 
>> but it doesn't seem to work:
>>
>> views.py
>>
>> def comment_upvote(request, comment_id):
>> comment = get_object_or_404(Comment.objects.filter(id__exact=
>> comment_id,approved=True))
>> if 'commentvote' + str(comment.id) not in request.session:
>> comment.upvotes = comment.upvotes + 1
>> comment.votes = comment.votes + 1
>> comment.save()
>> request.session['commentvote' + str(comment.id)] = True
>> else:
>> messages.error(request, 'You have already voted on this comment.'
>> )
>> return redirect('comments')
>>
>> The logic in the view is confirmed to work - It won't let you vote on the 
>> same comment twice.
>>
>> template
>>
>> {% with 'commentvote'|add:comment.id as voted %}
>> {% if not request.session.voted %}
>> > onclick="javascript:document.location.href='{% url 'comment_upvote' 
>> comment.id %}';">
>> 
>> 
>> > onclick="javascript:document.location.href='{% url 'comment_downvote' 
>> comment.id %}';">
>>  > span>
>> 
>> {% endif %}
>> {% endwith %}
>>
>> Any help would be appreciated!
>>
>
>
> I think you have the wrong data structure. Instead of storing all the 
> comment votes as separate keys in the session,  consider storing them in a 
> single "commentvotes" dictionary:
>
> votes = request.session.setdefault('commentvotes', {})
> if comment.id not in votes:
> ...
> votes[comment.id] = True
> else:
> ...
>
> and the template:
>
> {% if comment.id not in request.session.votes %}
>
> --
> Daniel.
>

-- 
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/f71917bf-05a2-4a02-920d-1a07dd23fe0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch in Django (url ploblem)

2015-07-02 Thread James Schneider
> > I'm a beginner of Django I want to set my url with database field_name
> > instead of use primary key from Django tutorial. This is my code.
> >
> > *mysite*
> > **dwru/urls.py**
> > urlpatterns = [
> > url(r'^$', include('product.urls', namespace="product")),
> > ]
>
> This regex is incorrect, and will only match a URL of '/', which is
> probably not what you want (since you are making other URL's like
> '/TestCA01' down below). You need to remove the $ from the regex to
> pass along the entire URL string to the include. You probably need a
> slash in there also to remove it as a prefix when it is passed along
> to the include:
>
> url(r'^/', include('product.urls', namespace="product")),
>

I was thinking about this and you may not need the /, if it doesn't work,
try without it. I'm not in front of a computer to verify.

-James

-- 
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/CA%2Be%2BciUD%2BvTpS71q2EGz8F-Qc9StWtOxx%3Df2WTHWmdtKzQX6Fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch in Django (url ploblem)

2015-07-02 Thread James Schneider
> I'm a beginner of Django I want to set my url with database field_name
> instead of use primary key from Django tutorial. This is my code.
>
> *mysite*
> **dwru/urls.py**
> urlpatterns = [
> url(r'^$', include('product.urls', namespace="product")),
> ]

This regex is incorrect, and will only match a URL of '/', which is
probably not what you want (since you are making other URL's like
'/TestCA01' down below). You need to remove the $ from the regex to
pass along the entire URL string to the include. You probably need a
slash in there also to remove it as a prefix when it is passed along
to the include:

url(r'^/', include('product.urls', namespace="product")),


>
> *myapp*
> **product/urls.py**
> urlpatterns = [
>url(r'^$', views.index, name='index'),
>url(r'^(?P[-_\w]+)/$', views.product_list_from_index,
> name='catalog'),
> ]


Assuming you fix the issue above, after a cursory glance this looks
fine. Just a note that \w includes the underscore, so you can remove
that as one of the potential matching characters.


>
> **product/views.py**
> def product_list_from_index(request, name_catalog):
>catalog = get_object_or_404(Catalog, name_catalog=name_catalog)
>context = {
>'catalog': catalog
> }
>return render(request,'product/product_list.html', context)
>
>
> **product/models.py**
> class Catalog(models.Model):
>   name_catalog = models.CharField(max_length=45)
>   product = models.ManyToManyField(Product)
>
> **template/product/index.html**
> {% for catalog in catalog_list %}
> {{
> catalog.name_catalog }}
> {% endfor %}
>
> Then I add Catalog field with "TestCa01" then it shown an error
>
> NoReverseMatch at /
> Reverse for 'catalog' with arguments '(u'TestCa01',)' and keyword arguments
> '{}' not found. 1 pattern(s) tried: [u'$(?P[-_\\w]+)/$']
>

It's odd that the regex is showing prefixed with a $ (I can't recall
seeing that before), that would indicate that it is looking for the
end of the line at the beginning of the regex statement, which means
the rest of the statement will never match. This may be an artifact
from the regex issue above.


> it kind of some problem with this line in template
>
> {% url 'product:catalog' catalog.name_catalog %}
>
> any Idea?
>

Unfortunately, it's hard to pinpoint in the error message what exactly
broke. Someone submitted a ticket a while back to make the error
message more concise and point people back to their URL confs. It was
closed because the list of URL regex's is now displayed.

https://code.djangoproject.com/ticket/14343


While I'm not deeply familiar with the code behind the URL resolver
functions, fixing the initial regex will need to be done regardless.
My wild guess would be that it properly fills in the value for
P, but sine the include statement is incorrect (and will
ignore anything after the initial / in the requested URL), the string
doesn't match  when the regex is checked.

-James

-- 
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/CA%2Be%2BciVVL53juBEM1fz_uJrQkaY76iiyy02nxv1CRxUkiDodAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django model for non web applications

2015-07-02 Thread Russell Keith-Magee
On Thu, Jul 2, 2015 at 12:50 AM, Jeff Fritz  wrote:

> I'm fairly new to Django and making my way through the tutorial.
>
> Knowing what I've learned so far, I'd like to explore using
> django.db.models.Model in a non-web application. I'd like to take the
> entire model layer and use it for database access in a standalone,
> multithreaded python 3.4 application. It is not a web application. I would
> like to be able to take advantage of the migration capabilities in
> manage.py.
>
> Questions:
>
> 1. Is it as simple as adding `from djanago.db import models`? Would this
> bring in any unnecessary django packages/modules, considering I will not be
> developing a web application, not using views, templating, etc?
>

It's *almost* this simple - you will also need to configure your Django
environment before you start making database calls. If you're looking to do
this in a *completely* "non-web" way, this probably means a call to
settings.configure(); details here:

https://docs.djangoproject.com/en/1.8/topics/settings/


> 2. Is the django model layer thread safe? Specifically, when using sqlite3
> as a back end?
>

It should be - after all, web servers are frequently multi-threaded.
SQLite3's performance under multithreading, however, might leave something
to be desired.


> 3. Are there other clean ORM/database model layer frameworks/packages that
> I should consider for python 3.4?
>

The other obvious candidate would be SQLAlchemy; it's a perfectly fine ORM
- without any of the other web framework overhead. It's a lot more like a
"SQL building toolkit" than Django's ORM - whether this is a good or bad
thing depends on your own preferences and use case.

Yours,
Russ Magee %-)

-- 
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/CAJxq848qKXu3GT6kpwLzvd1-V-a6eTjw%2BByY-XATTk1DiKVpGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Access dynamic session variable name in template

2015-07-02 Thread Daniel Roseman
On Thursday, 2 July 2015 19:09:59 UTC+1, jorr...@gmail.com wrote:
>
> Hi everyone,
>
> I am trying to keep track of who has voted on a comment by setting session 
> variables like 'commentvote1', 'commentvote2', etc to True. These variable 
> names are dynamically generated based on the id of the comment. How can I 
> access these dynamic variables in my template? I've tried this but it 
> doesn't seem to work:
>
> views.py
>
> def comment_upvote(request, comment_id):
> comment = get_object_or_404(Comment.objects.filter(id__exact=
> comment_id,approved=True))
> if 'commentvote' + str(comment.id) not in request.session:
> comment.upvotes = comment.upvotes + 1
> comment.votes = comment.votes + 1
> comment.save()
> request.session['commentvote' + str(comment.id)] = True
> else:
> messages.error(request, 'You have already voted on this comment.')
> return redirect('comments')
>
> The logic in the view is confirmed to work - It won't let you vote on the 
> same comment twice.
>
> template
>
> {% with 'commentvote'|add:comment.id as voted %}
> {% if not request.session.voted %}
>  onclick="javascript:document.location.href='{% url 'comment_upvote' 
> comment.id %}';">
> 
> 
>  onclick="javascript:document.location.href='{% url 'comment_downvote' 
> comment.id %}';">
>   span>
> 
> {% endif %}
> {% endwith %}
>
> Any help would be appreciated!
>


I think you have the wrong data structure. Instead of storing all the 
comment votes as separate keys in the session,  consider storing them in a 
single "commentvotes" dictionary:

votes = request.session.setdefault('commentvotes', {})
if comment.id not in votes:
...
votes[comment.id] = True
else:
...

and the template:

{% if comment.id not in request.session.votes %}

--
Daniel.

-- 
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/19223e2f-f70b-43d7-8f60-a9cf829512b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Access dynamic session variable name in template

2015-07-02 Thread jorrit787
Hi everyone,

I am trying to keep track of who has voted on a comment by setting session 
variables like 'commentvote1', 'commentvote2', etc to True. These variable 
names are dynamically generated based on the id of the comment. How can I 
access these dynamic variables in my template? I've tried this but it 
doesn't seem to work:

views.py

def comment_upvote(request, comment_id):
comment = get_object_or_404(Comment.objects.filter(id__exact=comment_id,
approved=True))
if 'commentvote' + str(comment.id) not in request.session:
comment.upvotes = comment.upvotes + 1
comment.votes = comment.votes + 1
comment.save()
request.session['commentvote' + str(comment.id)] = True
else:
messages.error(request, 'You have already voted on this comment.')
return redirect('comments')

The logic in the view is confirmed to work - It won't let you vote on the 
same comment twice.

template

{% with 'commentvote'|add:comment.id as voted %}
{% if not request.session.voted %}




 

{% endif %}
{% endwith %}

Any help would be appreciated!

-- 
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/6409d0b4-ac59-4054-95ef-f3a018554148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help me develop a Job Tracker (?)

2015-07-02 Thread Javier Guerra Giraldez
On Thu, Jul 2, 2015 at 10:26 AM, Softeisbieger  wrote:
> I am currently thinking about the database representation. I don't think I
> can solve this with django-viewflow: I need to be able to specify in advance
> a deadline and an assignee for each task of a work flow.


first of all, its important to note that a full-featured workflow
engine is Turing-complete, so it's theoretically undecidable.  There
are limits on what kind of tools an automated system can provide.
specifically, it's easy to write workflows for which it's impossible
to calculate a detailed schedule.

if you want your system to be able to define deadlines for each task
given a final deadline, or some useful "%-done" indicator, then you
might be better served by a "limited shape" workflow model.  The
simplest case (yet widely used) is a linear pipeline of tasks, which
can look similar to what you describe.

with a linear pipeline, it's easy to set time estimates for each step,
to calculate proposed milestone dates backward from the final deadline
date.  If you get behind schedule, it could even estimate "tight
goals" by proportionally distributing the remaining time between the
remaining tasks.

some limitations of the linear model can be relaxed by defining some
steps as "optional", or allowing some authorizations to skip a task,
or by specifying the prerequisites of a task as not necessarily "all
the previous steps".


if you still want the wide flexibility of a full-featured workflow
engine, recognize that it's not easy for most people to think in terms
of abstract states, and planning all the interdependences between
steps of any slightly complex process is in fact a programming
activity, even if done graphically.  IOW, if you ask users to
repeatedly one-shot workflows, they will naturally limit themselves to
simple lists of tasks and manage any unexpected circumstances by
(ab)using 'override' permissions.

workflow engines shine if you have a mid-to-large group of people
doing some complex process repeatedly.  a good example (and one where
i've found them quite a lifesaver) is in the publishing industry: you
have several editing steps, with well-defined approval points, and
rules of when some work must be redone, discarded, or rushed.  and it
must be done again and again, for each campaign, so it pays up to do a
very detailed model.


note that a state-transitions diagram is usually drawn as several
circles connected by arrows.  The tasks are associated to the arrows
(transitions), not the the circles (states).  Also, in most engines,
each transition has some permission restrictions and maybe a way to
specify preconditions, which makes it easy to show, for a given user,
which are the transitions available for a specific process.


good luck!

-- 
Javier

-- 
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/CAFkDaoS3bC6NZUYD%2Bu6D00g67tKSfH6vcJhwKv0a6R_Vd%2BdTZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help me develop a Job Tracker (?)

2015-07-02 Thread Softeisbieger
I am currently thinking about the database representation. I don't think I 
can solve this with django-viewflow: I need to be able to specify in 
advance a deadline and an assignee for each task of a work flow.

Maybe consider the following: A work flow consists of a number of tasks. 
Each task is followed by another task or 'end'. Each task has a predecessor 
which is either another task or 'start'. Now model a task which contains 
some information and the primary key of it predecessor and successor. A 
work flow contains a description and the primary key of the currently 
active task. The advantage is that in this way a work flow can consist of 
any number of tasks. The user then could define a template work flow where 
for example the assignee of some task (or all) is predefined. New work 
flows can then be started using either a template or a new definition from 
scratch.

Maybe you could give me some input. I am not to familiar with all this 
stuff...

-- 
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/6f967565-8b58-46d9-8a6d-a190f7b4b828%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating model (table) inheritance in Django 1.8 using PostgreSQL

2015-07-02 Thread Some Developer

On 02/07/15 13:56, Vijay Khemlani wrote:

You could dynamically create a ModelForm based on the model class:

from django.forms import ModelForm

MetaClass = type('Meta', (), {'model': ProductItemText})

MetaModelForm = type('ProductModelForm', (ModelForm, ), {'Meta': MetaClass})

form = MetaModelForm()

The only thing you would need is the model class itself
("ProductItemText" in this particular case),  I think you could even add
it as a classmethod to the base Product class.


Hi,

Thanks for the reply.

I'm a bit confused about what this does. Can you explain a little bit. 
I'd like to understand what is going on in the above code a little better.


Thanks.

--
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/55953B40.2030701%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't Start Project.

2015-07-02 Thread Bill Freeman
SQLite persists your data in a file on the filesystem.  You get to choose
the name in settings.py.

Using other databases requires additional configuration, including getting
them installed, installing a python adapter that django supports, creating
a database user with suitable permissions, and more.  There's lots of fine
documentation on line at docs.djangoproject.com and elsewhere, and I'm not
going to attempt to duplicate it here.  Also, since I never run django (or
most things) anywhere but linux, I would probably run afoul of Windows nits
pretty quickly.

On Wed, Jul 1, 2015 at 9:08 PM, Steve Burrus 
wrote:

> "As long as you're happy with the default file name." What exactly are you
> referring to Bill? The database settings? Say how dpo you synch either
> mysql or the postgres database server into django anyway? I really haven't
> figured out yet how to do that I am afraid.
>
>
>
> On Wed, Jul 1, 2015 at 5:51 PM, Bill Freeman  wrote:
>
>> As long as you're happy with the default file name.
>>
>> On Wed, Jul 1, 2015 at 6:06 PM, Gergely Polonkai 
>> wrote:
>>
>>> No, Django does that for you. You only have to worry about DB settings
>>> if you want something else like MySQL or Postgres.
>>> On 1 Jul 2015 23:40, "Bill Freeman"  wrote:
>>>
 Yes.  syncdb should work, assuming that sqlite is available (I think
 that it's built in in all the python 3.x versions), and assuming that you
 have a correctly configured settings.py (startproject makes one, but you
 will still have things to enter, such as data base configuration info (like
 the file to use to back sqlite), or to edit, such as your timezone.

 On Wed, Jul 1, 2015 at 5:35 PM, Steve Burrus 
 wrote:

> no django was not installed so I did a quick "pip install django" and
> installed django 1.8.2 into my ins tance of virualenv and was [finally]
> able to connect to the django server. I assume trhat I can easily do the
> "python manage.py syncdb" to connect to the sqllite3 server?
>
>
> On Wed, Jul 1, 2015 at 3:58 PM, Bill Freeman 
> wrote:
>
>> It sounds like django isn't on your path.  If you are running in a
>> virtualenv, was django pip installed while running in that same 
>> environment?
>>
>> On Wed, Jul 1, 2015 at 4:26 PM, Steve Burrus > > wrote:
>>
>>> cd to the directory containing manage.py (the project directory),
>>> then: "python manage.py runserver" Yeah I just now did exact;ly that but
>>> STILL got the error message : "(steve)
>>> C:\Users\SteveB\Desktop\steve\src>python manage.py runserver Traceback
>>> (most recent call last):  File "manage.py", line 8, in  from
>>> django.core.management import execute_from_command_line ImportError:
>>> No module named django.core.management" I r enamed my newly created 
>>> project
>>> to "src".
>>>
>>>
>>> On Wed, Jul 1, 2015 at 3:14 PM, Bill Freeman 
>>> wrote:
>>>
 cd to the directory containing manage.py (the project directory),
 then:

   python manage.py runserver

 On Wed, Jul 1, 2015 at 2:04 PM, Steve Burrus <
 steveburru...@gmail.com> wrote:

> well I was able to create a new project earlier however I am now
> having trouble with starting the django ser ver. when I ran this 
> cpommand
> "python .\Scripts\django-admin.py runserver" I always get this error
> message : "python: can't open file '.\Scripts\django-admin.py': 
> [Errno 2]
> No such file or directory". What's going on for me to get this error?
>
> On Wednesday, July 1, 2015 at 10:27:14 AM UTC-5, Steve Burrus
> wrote:
>>
>> I need some help please with  tryiong to start a new Django
>> project. Here is the error message I always get when I try to do 
>> this. can
>> someone help me with this?
>>
>> "C:\Users\SteveB\Desktop\steve>.\Scripts\activate
>> (steve) C:\Users\SteveB\Desktop\steve>python
>> .\Scripts\django-admin.py startproject proj
>> python: can't open file '.\Scripts\django-admin.py': [Errno 2] No
>> such file or directory"
>>
>>
>>
>>  --
> 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/db741397-9c7c-4368-805c-07d60d6042bf%40googlegroups.com
> 

Re: Creating model (table) inheritance in Django 1.8 using PostgreSQL

2015-07-02 Thread Vijay Khemlani
You could dynamically create a ModelForm based on the model class:

from django.forms import ModelForm

MetaClass = type('Meta', (), {'model': ProductItemText})

MetaModelForm = type('ProductModelForm', (ModelForm, ), {'Meta': MetaClass})

form = MetaModelForm()

The only thing you would need is the model class itself ("ProductItemText"
in this particular case),  I think you could even add it as a classmethod
to the base Product class.





On Thu, Jul 2, 2015 at 9:34 AM, Some Developer 
wrote:

> I have a model which defines an item and many sub-models which inherit
> from it to define the type of the model. Something like this:
>
> Product(models.Model):
> owner = models.ForeignKey(settings.AUTH_USER_MODEL)
> name = models.CharField(max_length=255)
>
> ProductItemText(Product):
> type = models.TextField()
>
> ProductItemBoolean(Product):
> type = models.BooleanField()
>
> etc etc. There are a lot more different sub-models for different types.
>
> I'm a bit confused about how to generate a form based on the type that the
> user wants to add to the database. Do you have to have a form each
> individual sub-type or is there a nice workaround for this specific problem?
>
> Any help is appreciated.
>
> --
> 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/55952FDF.8000604%40googlemail.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/CALn3ei2Cgh_nmmvJrKgzCcErRaKEQ5L6PJcPGA%2Bwch07bk2mag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Creating model (table) inheritance in Django 1.8 using PostgreSQL

2015-07-02 Thread Some Developer
I have a model which defines an item and many sub-models which inherit 
from it to define the type of the model. Something like this:


Product(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
name = models.CharField(max_length=255)

ProductItemText(Product):
type = models.TextField()

ProductItemBoolean(Product):
type = models.BooleanField()

etc etc. There are a lot more different sub-models for different types.

I'm a bit confused about how to generate a form based on the type that 
the user wants to add to the database. Do you have to have a form each 
individual sub-type or is there a nice workaround for this specific problem?


Any help is appreciated.

--
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/55952FDF.8000604%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch in Django (url ploblem)

2015-07-02 Thread Jeff Gaoey


I'm a beginner of Django I want to set my url with database field_name 
instead of use primary key from Django tutorial. This is my code.

*mysite***dwru/urls.py**
urlpatterns = [
url(r'^$', include('product.urls', namespace="product")),]
*myapp***product/urls.py**
urlpatterns = [
   url(r'^$', views.index, name='index'),
   url(r'^(?P[-_\w]+)/$', views.product_list_from_index, 
name='catalog'),]
**product/views.py**def product_list_from_index(request, name_catalog):
   catalog = get_object_or_404(Catalog, name_catalog=name_catalog)
   context = {
   'catalog': catalog}
   return render(request,'product/product_list.html', context)

**product/models.py**class Catalog(models.Model):
  name_catalog = models.CharField(max_length=45)
  product = models.ManyToManyField(Product)
**template/product/index.html**{% for catalog in catalog_list %}
{{ 
catalog.name_catalog }}{% endfor %}

Then I add Catalog field with "TestCa01" then it shown an error

NoReverseMatch at /Reverse for 'catalog' with arguments '(u'TestCa01',)' and 
keyword arguments '{}' not found. 1 pattern(s) tried: 
[u'$(?P[-_\\w]+)/$']

it kind of some problem with this line in template

{% url 'product:catalog' catalog.name_catalog %}

any Idea?

-- 
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/65b8fb8e-02ae-4441-88cc-114eb662cdee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.