return values from static files to django admin

2015-10-29 Thread dc
I have declared a charfield 'choice_text' in one of my models. I want to 
convert it to a dropdown box in django admin. The choices in the dropdown 
list depend on user input to a textbox defined in another model class. I 
have a javascript (declared  as Media class inside a ModelAdmin class) that 
reads user input in the textbox. But I am unable to this choice list back 
from .js file to django admin. How do I do that? Thanks in advance.

I have tried this.

*models.py*
class Routing(models.Model):
choice_text = models.CharField(_('Choices'), max_length=100, 
default="(any)", null=False)

*admin.py*
class AdminRoutingInlineForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AdminRoutingInlineForm, self).__init__(*args, **kwargs)
CHOICES = [('a', 'any'),('b', 'blah'),] * // override this with 
choices from populate_dropdown.js (code below)*
self.fields['choice_text'].choices = CHOICES

class RoutingInlineAdmin(StackedInline):
form = AdminRoutingInlineForm
fields = (('choice_text', 'next'),)
model = Routing


class FormModelAdmin(ModelAdmin):
inlines = [RoutingInlineAdmin]

class Media:
js= ("sforms/admin/populate_dropdown.js",)


*populate_dropdown.js*
(function($) {
$(document).ready(function() {
   
$("[id^=id_fields-][id$=_options_0]").each(function(){ *  // 
user input from this field will be used as choices*
choices = '(any),' + $(this).val().split("\n");
alert(choices);

*// send this choices back to admin.py and override CHOICES 
in AdminRoutingInlineForm class*
});  
});
 


-- 
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/dc21af05-5d8a-4fd5-8f8c-8e303192576a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MySQL queries-connection to django

2015-10-29 Thread Dheerendra Rathor
Hi, Django docs discuss about mysql connection here
https://docs.djangoproject.com/en/1.8/ref/databases/#mysql-db-api-drivers

On Fri, 30 Oct 2015 at 07:12 Sid  wrote:

> So there is any way before creating model we can connect django sql server
> 2012
>
>
> On Wednesday, October 28, 2015 at 11:18:37 PM UTC-4, Mike Dewhirst wrote:
>
>> On 29/10/2015 7:00 AM, Sid wrote:
>> > I am new to DJANGO...
>>
>> You can connect to your database using Django but first Django needs to
>> have a model of each table in your database so it knows what to look
>> for. https://docs.djangoproject.com/en/1.8/howto/legacy-databases/
>>
>> There is a management command which will analyse your database and
>> automatically create those models.
>>
>> https://docs.djangoproject.com/en/1.8/howto/legacy-databases/#auto-generate-the-models
>>
>> But if you are new to Django it would be best to come up to speed with a
>> broader knowledge of the way things work. There is an excellent tutorial
>> ... https://docs.djangoproject.com/en/1.8/ ... which will take you step
>> by step through the general learning curve.
>>
>> Welcome and good luck
>>
>> Mike
>>
>>
>> > so i have installed django,python and using Visual studio as interface,
>> > so my question is I have database name :*siddharth* Â in sql server:Â
>> > *63-W7-MJ021R04\ALMDATA* i want to connect my database(siddharth) to
>> > django using settings.py, But i am not understanding how to do it
>> > There are any other installations I have to do it to connect or I can
>> > use my database directly.
>> > Can anyone please tell me the procedure it wil be very helpful
>> >
>> > Your help is much appreciated.
>> > 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...@googlegroups.com
>> > .
>> > To post to this group, send email to django...@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/11363af6-28e1-43e4-bbad-40aea634e23c%40googlegroups.com
>> > <
>> https://groups.google.com/d/msgid/django-users/11363af6-28e1-43e4-bbad-40aea634e23c%40googlegroups.com?utm_medium=email_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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ac0ee56a-5e78-42db-9c62-33fe5bbefbd3%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAByqUghicSCfLCm7HxwNPO9yiQHkcRvw%3DX3g927YEH%2BmW50a%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: MySQL queries-connection to django

2015-10-29 Thread Sid
So there is any way before creating model we can connect django sql server 
2012

On Wednesday, October 28, 2015 at 11:18:37 PM UTC-4, Mike Dewhirst wrote:
>
> On 29/10/2015 7:00 AM, Sid wrote: 
> > I am new to DJANGO... 
>
> You can connect to your database using Django but first Django needs to 
> have a model of each table in your database so it knows what to look 
> for. https://docs.djangoproject.com/en/1.8/howto/legacy-databases/ 
>
> There is a management command which will analyse your database and 
> automatically create those models. 
>
> https://docs.djangoproject.com/en/1.8/howto/legacy-databases/#auto-generate-the-models
>  
>
> But if you are new to Django it would be best to come up to speed with a 
> broader knowledge of the way things work. There is an excellent tutorial 
> ... https://docs.djangoproject.com/en/1.8/ ... which will take you step 
> by step through the general learning curve. 
>
> Welcome and good luck 
>
> Mike 
>
>
> > so i have installed django,python and using Visual studio as interface, 
> > so my question is I have database name :*siddharth* Â in sql server:Â 
> > *63-W7-MJ021R04\ALMDATA* i want to connect my database(siddharth) to 
> > django using settings.py, But i am not understanding how to do it 
> > There are any other installations I have to do it to connect or I can 
> > use my database directly. 
> > Can anyone please tell me the procedure it wil be very helpful 
> > 
> > Your help is much appreciated. 
> > 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...@googlegroups.com  
> > . 
> > To post to this group, send email to django...@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/11363af6-28e1-43e4-bbad-40aea634e23c%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/11363af6-28e1-43e4-bbad-40aea634e23c%40googlegroups.com?utm_medium=email_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ac0ee56a-5e78-42db-9c62-33fe5bbefbd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


mssql databASE CONNECTION to Django

2015-10-29 Thread Sid
*Hi all,*
I am trying to connect database which is in server to django, but it is 
showing many errors like(platform i am using M visual studio)

*Traceback (most recent call last):*
  File "C:\Users\speesary\Desktop\programs\learn\learn\manage.py", line 17, 
in 
execute_from_command_line(sys.argv)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\core\management\__init__.py",
 
line 351, in execute_from_command_line
utility.execute()
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\core\management\__init__.py",
 
line 325, in execute
django.setup()
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\__init__.py",
 
line 18, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\apps\registry.py",
 
line 108, in populate
app_config.import_models(all_models)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\apps\config.py",
 
line 198, in import_models
self.models_module = import_module(models_module_name)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\importlib\__init__.py", 
line 37, in import_module
__import__(name)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\contrib\auth\models.py",
 
line 41, in 
class Permission(models.Model):
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\models\base.py",
 
line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\models\base.py",
 
line 324, in add_to_class
value.contribute_to_class(cls, name)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\models\options.py",
 
line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, 
connection.ops.max_name_length())
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\__init__.py",
 
line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\utils.py",
 
line 240, in __getitem__
backend = load_backend(db['ENGINE'])
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\utils.py",
 
line 111, in load_backend
return import_module('%s.base' % backend_name)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\importlib\__init__.py", 
line 37, in import_module
__import__(name)
  File 
"C:\Users\speesary\AppData\Local\Continuum\Anaconda\lib\site-packages\django-1.8.5-py2.7.egg\django\db\backends\sqlserver_ado\base.py",
 
line 5, in 
from django.db.backends import BaseDatabaseWrapper, 
BaseDatabaseFeatures, BaseDatabaseValidation, BaseDatabaseClient
ImportError: cannot import name BaseDatabaseWrapper
The Python REPL process has exited

code in my *settings.py*
*PACKAGES ADDED:*
*from django.db.backends.base.base import BaseDatabaseWrapperfrom 
django.db.backends.base.client import BaseDatabaseClientfrom 
django.db.backends.base.creation import BaseDatabaseCreationfrom 
django.db.backends.base.features import BaseDatabaseFeaturesfrom 
django.db.backends.base.introspection import BaseDatabaseIntrospection#from 
django.db.backends.base.introspection import FieldInfo, TableInfofrom 
django.db.backends.base.operations import BaseDatabaseOperationsfrom 
django.db.backends.base.schema import BaseDatabaseSchemaEditorfrom 
django.db.backends.base.validation import BaseDatabaseValidationfrom 
django.db.backends.util import CursorWrapperfrom os import path*

'default': {
'ENGINE': 'django.db.backends.sqlserver_ado'  , 
  
 #'django.db.backends.sqlserver_ado'
'NAME': 'Siddharth',
'USER': 'SCGLOBAL\speesary@ALMDATA',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT':'',
'OPTIONS': {
 
'driver':'SQL Server Native Client 11.0',
'MARS_Connection': True,
can anyone please tell me the procedure how to do it. it will be very 
helpful...
your help is much appreciated

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 

Re: django filebrowser decoding

2015-10-29 Thread 'Tom Evans' via Django users
On Thu, Oct 29, 2015 at 8:35 PM, Emīls Brass  wrote:
> I got django filebrowser for admin, where admin can see all added files in
> special folder.
>
> When admin click on folder to see whats inside, if there is some file with
> name who contains UNICODE chartacter, then I shows 500 error, but if not,
> everything is working.
>
> We exported this webpage to new server, on old server everything where
> working good, but on new server we got this problem, but all website file
> are the same, so, I think that problem could be in some python libary files,
> I need some plugin or something like that to be installed, but what?
>
> Example:
> Userfiles/folder1/abcde.pdf - all working good
> Userfiles/folder2/ābčdē.pdf - not working, 500 error
>
> On log file I got this message - UnicodeEncodeError: 'ascii' codec can't
> encode characters in position 0-5: ordinal not in range(128)
>

The locale on the new server is the C locale, and is not the same as
the locale on the old server, which was some UTF-8 locale.

Consult the documentation for the webserver you use to host django,
and ensure that the LANG is set appropriately. Searching google for
" LANG" should show appropriate results.

Cheers

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/CAFHbX1LEniOEh%3DXEaTWZnfyHc7RopU%3D2vSEVeH6FJZ8U%3D8TH8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django filebrowser decoding

2015-10-29 Thread Dheerendra Rathor
Do you have the full stacktrace? Can you post that here?
On Fri, 30 Oct 2015 at 02:37 Emīls Brass  wrote:

> I got django filebrowser for admin, where admin can see all added files in
> special folder.
>
> When admin click on folder to see whats inside, if there is some file with
> name who contains UNICODE chartacter, then I shows 500 error, but if not,
> everything is working.
>
> We exported this webpage to new server, on old server everything where
> working good, but on new server we got this problem, but all website file
> are the same, so, I think that problem could be in some python libary
> files, I need some plugin or something like that to be installed, but what?
>
> Example:
> Userfiles/folder1/abcde.pdf - all working good
> Userfiles/folder2/ābčdē.pdf - not working, 500 error
>
> On log file I got this message - UnicodeEncodeError: 'ascii' codec can't
> encode characters in position 0-5: ordinal not in range(128)
>
> --
> 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/7657a070-5f0b-45d7-b66f-6ff13793d7c9%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAByqUgh7z%2BdoFotRsOLVBbXn8xXWs%2BO8sgDBLoqQF1JAR3SWaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django filebrowser decoding

2015-10-29 Thread Emīls Brass
I got admin panel, where you can see all files and folders added in website 
folder - userfiles, but there is a problem. 

When I oppening folder with files whos names contains with UNICODE, that 
map dosnt open, but I got 500 error, but if there is no files with UNICODE 
names it works.

Example:
UserFiles/FOLDER1/abcd.pdf - not working (500 error)
UserFiles/FOLDER2/ābčd.pdf - working

But problem isnt in files, I think so, because, this website was on server 
1 and everything were working, but now we moved to server 2, but now we got 
this problem, but files are the same. So, problem could be in some python 
libary files or somewhere there, I need some plugin. If there is something 
to fix this, some plugin or smthing?

-- 
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/9bd0a38b-4669-4705-a189-6efaba704fe4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django filebrowser decoding

2015-10-29 Thread Emīls Brass
I got django filebrowser for admin, where admin can see all added files in 
special folder.

When admin click on folder to see whats inside, if there is some file with 
name who contains UNICODE chartacter, then I shows 500 error, but if not, 
everything is working. 

We exported this webpage to new server, on old server everything where 
working good, but on new server we got this problem, but all website file 
are the same, so, I think that problem could be in some python libary 
files, I need some plugin or something like that to be installed, but what?

Example:
Userfiles/folder1/abcde.pdf - all working good
Userfiles/folder2/ābčdē.pdf - not working, 500 error

On log file I got this message - UnicodeEncodeError: 'ascii' codec can't 
encode characters in position 0-5: ordinal not in range(128)

-- 
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/7657a070-5f0b-45d7-b66f-6ff13793d7c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: formset concurrency control

2015-10-29 Thread Carsten Fuchs

Hi all,

continuing my previous post, I've implemented most of the ideas mentioned in this thread 
now, and would like, for completeness and future reference, add some related findings 
and thoughts:


As mentioned in my previous post, reconstructing the formset's initial data (the 
queryset) in the POST request by the same parameters that were used to construct the 
queryset for the initial formset data in the GET request, in *addition* to the primary 
keys received in the POST request, turned out to work very well. That is, the code is 
roughly like this:


# Inits is made from the view's appropriate queryset.
Inits = ...

# In the case of the GET request:
formset = TestFormSet(initial=Inits)

# In the case of the POST request:
formset = TestFormSet(request.POST, initial=Inits)


This is how the initial data is useful in the POST request:

  - It is required for validation in order to be able to detect "high-level" kinds of 
concurrency related mismatches (number of instances changed, deleted instances, 
unexpected new or replaced instances).


  - We also need the same data for "low-level" concurrency control, e.g. checking a 
`VERSION` number as e.g. in [1] and [2].


  - As a side effect of the same validation steps, tampering with the POST data is 
detected as well.


  - The initial data (`Inits` above) is also a convenient place for storing arbitrary 
extra data, e.g. the actual model instances, that can be used for rendering additional 
information in the template.


  - In the case of successful formset validation, the readily available queryset 
instances can be used for storing and saving the submitted data.



I still use custom Forms for all this, not ModelForms, because:

  - As we need the model instances anyway and already got them via the queryset as 
described above, using a ModelForm(-set) that implicitly instantiates them all again 
would not be efficient.


  - I have a lot of cases where I have a field flagged as "required" in the model, but 
"not required" in the form. This helps with making entire forms optional in the formset 
(won't get saved if not filled out), but makes clear what is required when a model is 
eventually saved. This is especially helpful when forms are rendered for which not 
necessarily a model instance exists and is not necessarily created, as e.g. in my 
CalenderEntry example described in another post of this thread ([3]).


  - Foreign keys are problematic. Although a ModelForm covers a FK just as it covers 
the model's PK, if we wish to extend the concept of validating `VERSION` numbers (as 
above) also to the related models, the form must be augmented with an appropriate 
version number field for each FK. (I have not checked, but adding such extra fields is 
probably possible with ModelForms as well.)



Well, so far my findings. Although this seems to work well, I'd very much appreciate any 
further comments and thoughts.


Best regards,
Carsten


[1] https://github.com/saxix/django-concurrency
[2] https://github.com/gavinwahl/django-optimistic-lock
[3] https://groups.google.com/d/msg/django-users/R7wJBTlC8ZM/N3dNlMrGCwAJ


--
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/5632477F.4050107%40cafu.de.
For more options, visit https://groups.google.com/d/optout.