Search Results

Search found 15813 results on 633 pages for 'django settings'.

Page 30/633 | < Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >

  • Correct redirect after posting comment - django comments framework

    - by Sachin
    I am using django comments framework for allowing users to comment on my site, but there is a problem with the url to which user is redirected after posting the comment. If I render my comment form as {% with comment.content_object.get_absolute_url as next %} {% render_comment_form for comment.content_object %} {% endwith %} Then the url to which it is redirected after the comment is posted is <comment.content_object.get_absolute_url/?c=<comment.id> For example I posted a comment on a post with url /post/256/a-new-post/ then the url to which I am redirected after posting the comment is /post/256/a-new-post/?c=99 where assume 99 is the id comment just posted. Instead what I want is something like this /post/256/a-new-post/#c99. Secondly when I do comment.get_absolute_url() I do not get the proper url instead I get a url like /comments/cr/58/14/#c99 and this link is broken. How can I get the correct url as mentioned in the documentation. Am i doing something wrong. Any help is appreciated.

    Read the article

  • Django adminsite customize search_fields query

    - by dArignac
    Howdy! In the django admin you can set the search_fields for the ModelAdmin to be able to search over the properties given there. My model class has a property that is not a real model property, means it is not within the database table. The property relates to another database table that is not tied to the current model through relations. But I want to be able to search over it, so I have to somehow customize the query the admin site creates to do the filtering when the search field was filled - is this possible and if, how? I can query the database table of my custom property and it then returns the ids of the model classes fitting the search. This then, as I said, has to flow into the admin site search query. Thanks!

    Read the article

  • Django User "per project" group assignation

    - by Ben G
    Hi, Here's my problem : my site has users, which can create projects, and access other user's projects. Each project can assign different rights to users. So, i could have Project A : user "John" is in group "manager" , and Project "B" user "John" is in group "worker". How could I use the Django User authentication model to do that ? From a SQL point a view, what i would like is to be able to add "project_id" in the primary key for the "auth_user_groups" table. I don't think profile is of any help here. Any advice ? UPDATE : "worker" and "manager" are just two examples of the permission group (or "roles") that my application defines. There will be more in the future. Eg : i will probably also have "admin", "reporting", etc...

    Read the article

  • Android SQLiteConstraintException: error code 19: constraint failed

    - by Tom D
    I've seen other questions about this exception, but all of them seem to be resolved with the solution that a row with the primary key specified already exists. This doesn't seem to be the case for me. I have tried replacing all single quotes in my strings with double quotes, but the same problem occurs. I'm trying to insert a row into the Settings table of the SQLite database I've created by doing the following: db.execSQL("DROP TABLE IF EXISTS "+Settings.SETTINGS_TABLE_NAME + ";"); db.execSQL(CREATE_MEDIA_TABLE); db.execSQL(CREATE_SETTINGS_TABLE); Cursor c = getAllSettings(); //If there isn't already a settings row, create a row full of defaults if(c.getCount()==0){ ContentValues cv = new ContentValues(); cv.put(Settings.SETTING_UNIQUE_ID, "'"+Settings.uniqueID+"'"); cv.put(Settings.SETTING_DEVICE_ID, Settings.SETTING_DEVICE_ID_DEFAULT); cv.put(Settings.SETTING_CONNECTION_PREFERENCE, Settings.SETTING_CONNECTION_PREFERENCE_DEFAULT); cv.put(Settings.SETTING_AD_HOC_ENABLED, Settings.SETTING_AD_HOC_ENABLED_DEFAULT); cv.put(Settings.SETTING_SERVER_ADDRESS, Settings.SETTING_SERVER_ADDRESS_DEFAULT); cv.put(Settings.SETTING_RECORDING_MODE, Settings.SETTING_RECORDING_MODE_DEFAULT); cv.put(Settings.SETTING_PREVIEW_ENABLED, Settings.SETTING_PREVIEW_ENABLED_DEFAULT); cv.put(Settings.SETTING_PICTURE_RESOLUTION_X, Settings.SETTING_PICTURE_RESOLUTION_X_DEFAULT); cv.put(Settings.SETTING_PICTURE_RESOLUTION_Y, Settings.SETTING_PICTURE_RESOLUTION_Y_DEFAULT); cv.put(Settings.SETTING_VIDEO_RESOLUTION_X, Settings.SETTING_VIDEO_RESOLUTION_X_DEFAULT); cv.put(Settings.SETTING_VIDEO_RESOLUTION_Y, Settings.SETTING_VIDEO_RESOLUTION_Y_DEFAULT); cv.put(Settings.SETTING_VIDEO_FPS, Settings.SETTING_VIDEO_FPS_DEFAULT); cv.put(Settings.SETTING_AUDIO_BITRATE_KBPS, Settings.SETTING_AUDIO_BITRATE_KBPS_DEFAULT); cv.put(Settings.SETTING_STORE_TO_SD, Settings.SETTING_STORE_TO_SD_DEFAULT); cv.put(Settings.SETTING_STORAGE_LIMIT_MB, Settings.SETTING_STORAGE_LIMIT_MB_DEFAULT); this.db.insert(Settings.SETTINGS_TABLE_NAME, null, cv); } The CREATE_SETTINGS_TABLE string is defined as the following: private static String CREATE_SETTINGS_TABLE = "CREATE TABLE IF NOT EXISTS " + Settings.SETTINGS_TABLE_NAME + "(" + Settings.SETTING_UNIQUE_ID + " TEXT NOT NULL PRIMARY KEY, " + Settings.SETTING_DEVICE_ID + " TEXT NOT NULL , " + Settings.SETTING_CONNECTION_PREFERENCE + " TEXT NOT NULL CHECK("+Settings.SETTING_CONNECTION_PREFERENCE+" IN("+Settings.SETTING_CONNECTION_PREFERENCE_ALLOWED+")), " + Settings.SETTING_AD_HOC_ENABLED + " TEXT NOT NULL CHECK("+Settings.SETTING_AD_HOC_ENABLED+" IN("+Settings.SETTING_AD_HOC_ENABLED_ALLOWED+")), " + Settings.SETTING_SERVER_ADDRESS + " TEXT NOT NULL, " + Settings.SETTING_RECORDING_MODE + " TEXT NOT NULL CHECK("+Settings.SETTING_RECORDING_MODE+" IN("+Settings.SETTING_RECORDING_MODE_ALLOWED+")), " + Settings.SETTING_PREVIEW_ENABLED + " TEXT NOT NULL CHECK("+Settings.SETTING_PREVIEW_ENABLED+" IN("+Settings.SETTING_PREVIEW_ENABLED_ALLOWED+")), " + Settings.SETTING_PICTURE_RESOLUTION_X + " TEXT NOT NULL, " + Settings.SETTING_PICTURE_RESOLUTION_Y + " TEXT NOT NULL, " + Settings.SETTING_VIDEO_RESOLUTION_X + " TEXT NOT NULL, " + Settings.SETTING_VIDEO_RESOLUTION_Y + " TEXT NOT NULL, " + Settings.SETTING_VIDEO_FPS + " TEXT NOT NULL, " + Settings.SETTING_AUDIO_BITRATE_KBPS + " TEXT NOT NULL, " + Settings.SETTING_STORE_TO_SD + " TEXT NOT NULL CHECK("+Settings.SETTING_STORE_TO_SD+" IN("+Settings.SETTING_STORE_TO_SD_ALLOWED+")), " + Settings.SETTING_STORAGE_LIMIT_MB + " TEXT NOT NULL )"; However, when I execute my insert, I always get: 03-19 19:37:36.974: ERROR/Database(386): Error inserting server_address='0.0.0.0' storage_limit='-1' connection='none' preview_enabled='0' sd_enabled='1' video_fps='15' audio_bitrate='96' device_id='-1' recording_mode='none' picture_resolution_x='-1' picture_resolution_y='-1' unique_id='000000000000000' adhoc_enable='0' video_resolution_x='320' video_resolution_y='240' 03-19 19:45:34.284: ERROR/Database(446): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed It seems as if all the columns in my insert are not null. The row's primary key HAS to be unique, because it's the only row in the table. Therefore, the only thing I can think of is my CHECK conditions aren't true. Here are the predefined strings I'm using: public static final String SETTING_UNIQUE_ID = "unique_id"; public static final String SETTING_DEVICE_ID = "device_id"; public static final String SETTING_DEVICE_ID_DEFAULT = "'-1'"; public static final String SETTING_CONNECTION_PREFERENCE = "connection"; public static final String SETTING_CONNECTION_PREFERENCE_3G = "'3g'"; public static final String SETTING_CONNECTION_PREFERENCE_WIFI = "'wifi'"; public static final String SETTING_CONNECTION_PREFERENCE_NONE = "'none'"; public static final String SETTING_CONNECTION_PREFERENCE_ALLOWED = SETTING_CONNECTION_PREFERENCE_3G+","+SETTING_CONNECTION_PREFERENCE_WIFI+","+SETTING_CONNECTION_PREFERENCE_NONE; public static final String SETTING_CONNECTION_PREFERENCE_DEFAULT = SETTING_CONNECTION_PREFERENCE_NONE; public static final String SETTING_AD_HOC_ENABLED = "adhoc_enable"; public static final String SETTING_AD_HOC_ENABLED_ALLOWED = TRUE+","+FALSE; public static final String SETTING_AD_HOC_ENABLED_DEFAULT = FALSE; public static final String SETTING_SERVER_ADDRESS = "server_address"; public static final String SETTING_SERVER_ADDRESS_DEFAULT = "'0.0.0.0'"; public static final String SETTING_RECORDING_MODE = "recording_mode"; public static final String SETTING_RECORDING_MODE_VIDEO = "'video'"; public static final String SETTING_RECORDING_MODE_AUDIO = "'audio'"; public static final String SETTING_RECORDING_MODE_PICTURE = "'picture'"; public static final String SETTING_RECORDING_MODE_NONE = "'none'"; public static final String SETTING_RECORDING_MODE_ALLOWED = SETTING_RECORDING_MODE_VIDEO+","+SETTING_RECORDING_MODE_AUDIO+","+SETTING_RECORDING_MODE_PICTURE+","+SETTING_RECORDING_MODE_NONE; public static final String SETTING_RECORDING_MODE_DEFAULT = SETTING_RECORDING_MODE_NONE; public static final String SETTING_PREVIEW_ENABLED = "preview_enabled"; public static final String SETTING_PREVIEW_ENABLED_ALLOWED = TRUE+","+FALSE; public static final String SETTING_PREVIEW_ENABLED_DEFAULT = FALSE; public static final String SETTING_PICTURE_RESOLUTION_X = "picture_resolution_x"; public static final String SETTING_PICTURE_RESOLUTION_X_DEFAULT = "'-1'"; public static final String SETTING_PICTURE_RESOLUTION_Y = "picture_resolution_y"; public static final String SETTING_PICTURE_RESOLUTION_Y_DEFAULT = "'-1'"; public static final String SETTING_VIDEO_RESOLUTION_X = "video_resolution_x"; public static final String SETTING_VIDEO_RESOLUTION_X_DEFAULT = "'320'"; public static final String SETTING_VIDEO_RESOLUTION_Y = "video_resolution_y"; public static final String SETTING_VIDEO_RESOLUTION_Y_DEFAULT = "'240'"; public static final String SETTING_VIDEO_FPS = "video_fps"; public static final String SETTING_VIDEO_FPS_DEFAULT = "'15'"; public static final String SETTING_AUDIO_BITRATE_KBPS = "audio_bitrate"; public static final String SETTING_AUDIO_BITRATE_KBPS_DEFAULT = "'96'"; public static final String SETTING_STORE_TO_SD = "sd_enabled"; public static final String SETTING_STORE_TO_SD_ALLOWED = TRUE+","+FALSE; public static final String SETTING_STORE_TO_SD_DEFAULT = TRUE; public static final String SETTING_STORAGE_LIMIT_MB = "storage_limit"; public static final String SETTING_STORAGE_LIMIT_MB_DEFAULT = "'-1'"; public static final String SETTING_CLIP_LENGTH_SECONDS = "clip_length"; public static final String SETTING_CLIP_LENGTH_SECONDS_DEFAULT = "'300'"; Does anyone see what could be going on? I'm stumped. Thanks in advance.

    Read the article

  • Django paging object has issues with Postgresql QuerySets

    - by pivotal
    I have some django code that runs fine on a SQLite database or on a MySQL database, but it runs into problems with Postgres, and it's making me crazy that no one has has this issue before. I think it may also be related to the way querysets are evaluated by the pager. In a view I have: def index(request, page=1): latest_posts = Post.objects.all().order_by('-pub_date') paginator = Paginator(latest_posts, 5) try: posts = paginator.page(page) except (EmptyPage, InvalidPage): posts = paginator.page(paginator.num_pages) return render_to_response('blog/index.html', {'posts' : posts}) And inside the template: {% for post in posts.object_list %} {# some rendering jazz #} {% endfor %} This works fine with SQLite, but Postgres gives me: Caught TypeError while rendering: 'NoneType' object is not callable To further complicate things, when I switch the Queryset call to: latest_posts = Post.objects.all() Everything works great. I've tried re-reading the documentation, but found nothing, although I admit I'm a bit clouded by frustration at this point. What am I missing? Thanks in advance.

    Read the article

  • Not work variables in django templates

    - by ??????? ???????
    My context dictionary not sending to my templates. I have function from django.shortcuts import render_to_response def home(request): return render_to_response('home.html',{'test':'test'}) and i have simple template such as: <html> <body> my test == {{test}} </body> </html> When i open my site in browser, i have "my test == ". settings.py is default. I dont use something custom. What the problem? Server is apache with wsgi module.

    Read the article

  • Problems using User model in django unit tests

    - by theycallmemorty
    I have the following django test case that is giving me errors: class MyTesting(unittest.TestCase): def setUp(self): self.u1 = User.objects.create(username='user1') self.up1 = UserProfile.objects.create(user=self.u1) def testA(self): ... def testB(self): ... When I run my tests, testA will pass sucessfully but before testB starts, I get the following error: IntegrityError: column username is not unique It's clear that it is trying to create self.u1 before each test case and finding that it already exists in the Database. How do I get it to properly clean up after each test case so that subsequent cases run correctly?

    Read the article

  • Django remove list_editable on a per row basis.

    - by Jason Leveille
    On the back of Django 1.2RC1, I have built a great administrator for my client! It's awesome. The client has one request that, if not satisfied, could bring this house of cards crashing down. I have a list of swim meet results. A meet result is added by a superuser. A team rep can edit a meet result (which they must be able to do inline, with list_editable), but after they edit the meet result inline and save, they should no longer be able to edit that result inline. They can only perform one edit. So, my question ... can I turn off list_editable on a per row basis?

    Read the article

  • Django - Passing arguments to models through ForeignKey attributes

    - by marshall
    I've got a class like this: class Image (models.Model): ... sizes = ((90,90), (300,250)) def resize_image(self): for size in sizes: ... and another class like this: class SomeClassWithAnImage (models.Model): ... an_image = models.ForeignKey(Image) what i'd like to do with that class is this: class SomeClassWithAnImage (models.Model): ... an_image = models.ForeignKey(Image, sizes=((90,90), (150, 120))) where i'm can specify the sizes that i want the Image class to use to resize itself as a argument rather than being hard coded on the class. I realise I could pass these in when calling resize_image if that was called directly but the idea is that the resize_image method is called automatically when the object is persisted to the db. if I try to pass arguments through the foreign key declaration like this i get an error straight away. is there an easy / better way to do this before I begin hacking down into django?

    Read the article

  • Access to field in extended flatpage in django

    - by Stanislav Feldman
    How to access field in extended flatpage in django? I wrote this: class ExtendedFlatPage(FlatPage): teaser = CharField(max_length=150) class ExtendedFlatPageForm(FlatpageForm): teaser = CharField(max_length=150) class Meta: model = ExtendedFlatPage class ExtendedFlatPageAdmin(FlatPageAdmin): form = ExtendedFlatPageForm fieldsets = ( (None, {'fields': ('url', 'title', 'teaser', 'content', 'sites',)}), ) admin.site.unregister(FlatPage) admin.site.register(ExtendedFlatPage, ExtendedFlatPageAdmin) And creation in admin is ok. But then in flatpages/default.html I tried this: <html> <body> <h1>{{ flatpage.title }}</h1> <strong>{{ flatpage.teaser }}</strong> <p>{{ flatpage.content }}</p> </body> </html> And there was no flatpage.teaser! What is wrong?

    Read the article

  • in django am facing url problem.....

    - by dpaksp
    am using django.0.97 version i have model called profile in that i have few fields eg like name ,email...ects and it's backend also ready..i.e database . and all users profile is created...i have given all permission to all users. when i login ,click on profile..i able to see list of all user name thr when i click on it ,it's goin to model page where i can edit the user profile..instead of that i want to navigate to a template when i can display the user details ,i have set the URl for it so that when url of that type request comes it should call a view from view it will call my template to display user details,.....the problem is it's not calling my view.... i think my problem is brief....if any information still required ?? pls ask me....and help me

    Read the article

  • (Django) Trim whitespaces from charField

    - by zardon
    How do I strip whitespaces (trim) from the end of a charField in Django? Here is my Model, as you can see I've tried putting in clean methods but these never get run. I've also tried doing name.strip(), models.charField().strip() but these do not work either. Is there a way to force the charField to trim automatically for me? Thanks. class Employee(models.Model): """(Workers, Staff, etc)""" name = models.CharField(blank=True, null=True, max_length=100) # This never gets run def clean_variable(self): data = self.cleaned_data['variable'].strip() return data def __unicode__(self): return self.name class Meta: verbose_name_plural = 'Employees' # This never gets run either class EmployeesForm(forms.ModelForm): class Meta: model = Employee def clean_description(self): #if not self.cleaned_data['description'].strip(): # raise forms.ValidationError('Your error message here') self.cleaned_data['name'].strip()

    Read the article

  • Override Django inlineformset_factory has_changed() to always return True

    - by John
    Hi, I am using the django inlineformset_factory function. a = get_object_or_404(ModelA, pk=id) FormSet = inlineformset_factory(ModelA, ModelB) if request.method == 'POST': metaform = FormSet (instance=a, data=request.POST) if metaform.is_valid(): f = metaform.save(commit=False) for instance in f: instance.updated_by = request.user instance.save() else: metaform = FormSet(instance=a) return render_to_response('nodes/form.html', {'form':metaform}) What is happening is that if I change any of the data then everything works ok and all the data gets updated. However if I don't change any of the data then the data is not updated. i.e. only entries which are changed go through the for loop to be saved. I guess this makes sense as there is no point saving data if it has not changed. However I need to go through and save every object in the form regardless of whether it has any changes on not. So my question is how do I override this so that it goes through and saves every record whether it has any changes or not? Hope this makes sense Thanks

    Read the article

  • Django: query spanning multiple many-to-many relationships

    - by Brant
    I've got some models set up like this: class AppGroup(models.Model): users = models.ManyToManyField(User) class Notification(models.Model): groups_to_notify = models.ManyToManyField(AppGroup) The User objects come from django's authentication system. Now, I am trying to get all the notifications pertaining to the groups that the current user is a part of. I have tried.. notifications = Notification.objects.filter(groups_to_notify=AppGroup.objects.filter(users=request.user)) But that gives an error: more than one row returned by a subquery used as an expression Which I suppose is because the groups_to_notify is checking against several groups. How can I grab all the notifications meant for the user based on the groups he is a part of?

    Read the article

  • Setting a preferred item of a many-to-one in Django

    - by Mike DeSimone
    I'm trying to create a Django model that handles the following: An Item can have several Names. One of the Names for an Item is its primary Name, i.e. the Name displayed given an Item. (The model names were changed to protect the innocent.) The models.py I've got looks like: class Item(models.Model): primaryName = models.OneToOneField("Name", verbose_name="Primary Name", related_name="_unused") def __unicode__(self): return self.primaryName.name class Name(models.Model): item = models.ForeignKey(Item) name = models.CharField(max_length=32, unique=True) def __unicode__(self): return self.name class Meta: ordering = [ 'name' ] The admin.py looks like: class NameInline(admin.TabularInline): model = Name class ItemAdmin(admin.ModelAdmin): inlines = [ NameInline ] admin.site.register(Item, ItemAdmin) It looks like the database schema is working fine, but I'm having trouble with the admin, so I'm not sure of anything at this point. My main questions are: How do I explain to the admin that primaryName needs to be one of the Names of the item being edited? Is there a way to automatically set primaryName to the first Name found, if primaryName is not set, since I'm using inline admin for the names?

    Read the article

  • Django test client gets 301 redirection when accessing url

    - by Michal Klich
    I am writing unittests for django views. I have observed that one of my views returns redirection code 301, which is not expected. Here is my views.py mentioned earlier. def index(request): return render(request, 'index.html', {'form': QueryForm()}) def query(request): if request.is_ajax(): form = QueryForm(request.POST) return HttpResponse('valid') Below is urls.py. urlpatterns = patterns('', url(r'^$', 'core.views.index'), url(r'^query/$', 'core.views.query') ) And unittest that will fail. def so_test(self): response = self.client.post('/') self.assertEquals(response.status_code, 200) response = self.client.post('/query', {}) self.assertEquals(response.status_code, 200) My question is: why there is status 301 returned?

    Read the article

  • ModelName(django.contrib.auth.models.User) vs ModelName(models.Model)

    - by amr.negm
    I am developing a django project. I created some apps, some of those are related to User model, for instance, I have a feeds app that handles user feeds, and another app that deals with extra user data like age, contacts, and friends. for each of these, I created a table that should be connected to the User model, which I using for storing and authenticating users. I found two ways to deal with this issue. One, is through extending User model to be like this: ModelName(User): friends = models.ManyToMany('self') ..... Two, is through adding a foreign key to the new table like this: ModelName(models.Model): user = models.ForeignKey(User, unique=True) friends = friends = models.ManyToMany('self') ...... I can't decide which to use in which case. in other words, what are the core differences between both?

    Read the article

  • Django admin proper urls inside listview

    - by hinnye
    Hi, My current target is to give users the chance to download CSV files from the admin site of my application. I successfully managed to create an additional column in the model's list view this way: def doc_link(self): return '<a href="files/%s">%s</a>' % (self.output, self.output) doc_link.allow_tags = True This shows the file name and creates the link, but sadly - because it's inside my 'searches' view - it has an URL: my_site/my_app/searches/files/13.csv. This is my problem, I would like to have my files stored in the admin media directory, like this: http://my_site/media/files/13.csv Does somebody know how to give url which points "outer" from the model's directory? Maybe somehow tell Django to use the ADMIN_MEDIA_PREFIX in the link? I'd really appreciate any help, thanks!

    Read the article

  • Saving data in a inherited django model

    - by aldeano
    I'm building an app to save data and some calculations made with those datas, the idea is keep the data in one model and the calculations in other. So, the models are like this: class FreshData(models.Model): name = models.CharField(max_length=20) one = models.IntegerField() two = models.IntegerField() def save(self, *args, **kwargs): Calculations() Calculations.three = self.one + self.two super(FreshData, self).save(*args, **kwargs) Calculations.save() class Calculations(FreshData): three = models.IntegerField() I've got a valueerror pointing out "self.one" and "self.two" as without value. I keep the idea in witch my design is wrong and django has a simpler way to store related data.

    Read the article

  • Django: Site-Wide URL Prefix

    - by Tom
    I've built a Django site that will live at the root when it's live. Right now it's functioning perfectly at the IP address. For testing purposes, the client has pointed a proxy url at it, but the url has /folder/path in it, so none of the URL patterns match. I put (/folder/path)? into all the url patterns so they now respond, but all of the links are broken because I'm using the {% url %} tag and while the url patterns will match the optional path, they don't include it in that tag. Clearly I can just hard-code /folder/path into all of my urls (well, into all of the url includes) until testing is complete, but is there a better way to do this?

    Read the article

  • Django model class and custom property

    - by dArignac
    Howdy - today a weird problem occured to me: I have a modle class in Django and added a custom property to it that shall not be saved into the database and therefore is not represent in the models structure: class Category(models.Model): groups = models.ManyToManyField(Group) title = defaultdict() Now, when I'm within the shell or writing a test and I do the following: c1 = Category.objects.create() c1.title['de'] = 'german title' print c1.title['de'] # prints "german title" c2 = Category.objects.create() print c2.title['de'] # prints "german title" <-- WTF? It seems that 'title' is kind of global. If I change title to a simple string it works as expected, so it has to do something with the dict? I also tried setting title as a property: title = property(_title) But that did not work, too. So, how can I solve this? Thank you in advance! enter code here

    Read the article

  • Django 1.2: Dates in admin forms don't work with Locales (I10N=True)

    - by equalium
    I have an application in Django 1.2. Language is selectable (I18N and Locale = True) When I select the english lang. in the site, the admin works OK. But when I change to any other language this is what happens with date inputs (spanish example): Correctly, the input accepts the spanish format %d/%m/%Y (Even selecting from the calendar, the date inserts as expected). But when I save the form and load it again, the date shows in the english form: %Y-%m-%d The real problem is that when I load the form to change any other text field and try to save it I get an error telling me to enter a valid date, so I have to write all dates again or change the language in the site to use the admin. I haven't specified anything for DATE_INPUT_FORMATS in settings nor have I overridden forms or models. Surely I am missing something but I can't find it. Can anybody give me a hint?

    Read the article

  • get foreign key objects in a single query - Django

    - by John
    Hi I have 2 models in my django code: class ModelA(models.Model): name = models.CharField(max_length=255) description = models.CharField(max_length=255) created_by = models.ForeignKey(User) class ModelB(models.Model): category = models.CharField(max_length=255) modela_link = models.ForeignKey(ModelA, 'modelb_link') functions = models.CharField(max_length=255) created_by = models.ForeignKey(User) Say ModelA has 100 records, all of which may or may not have links to ModelB Now say I want to get a list of every ModelA record along with the data from ModelB I would do: list_a = ModelA.objects.all() Then to get the data for ModelB I would have to do for i in list_a: i.additional_data = i.modelb_link.all() However this runs a query on every instance of i. Thus making 101 queries to run. Is there any way of running this all in just 1 query. Or at least less than the 101 queries. I've tried putting in ModelA.objects.select_related().all() but this didn't seem to have any effect. Thanks

    Read the article

  • Django Template - Convert python list into a javascript object

    - by amcashcow
    I am working on a django / python website I have a page where I want to display a table of search results The list of results is passed in to the template as normal I also want to make this list of objects accessible to the javascript code My first solution was just create another view that returned json format. But each page load required calling the query twice. So then I tried only downloading the data using the json view and printing the table using javascript. but this is also not desirable as now the presentation layer is mixed into the javascript code. is there a way to create a javascript object from the python list as the page is rendered?

    Read the article

  • Django: Converting an entire Model into a single dictionary

    - by LarrikJ
    Is there a good way in Django to convert an entire model to a dictionary? I mean, like this: class DictModel(models.Model): key = models.CharField(20) value = models.CharField(200) DictModel.objects.all().to_dict() ... with the result being a dictionary with the key/value pairs made up of records in the Model? Has anyone else seen this as being useful for them? Thanks. Update I just wanted to add is that my ultimate goal is to be able to do a simple variable lookup inside a Template. Something like: {{ DictModel.exampleKey }} With a result of DictModel.objects.get(key__exact=exampleKey).value Overall, though, you guys have really surprised me with how helpful allof your responses are, and how different the ways to approach it can be. Thanks a lot.

    Read the article

< Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >