Add admin edit form buttons (work with django 1.6)
I can't find any workable solution, so I wrote it. (Checked it on Django 1.6)
- admin
- form
- edit
- button
I can't find any workable solution, so I wrote it. (Checked it on Django 1.6)
Despite warning coming from django developers, I'm still using admin classes to quickly get into reverse engineering databases. One feature is missing: searching into fields thanks to a regex. One dirty solution I found is to overwrite get_search_results. But most of the code comes from django itself. If anyone has a better idea ;) **Usage:** 1. works since get_search_results is part of ModelAdmin (1.5 if I remember well) 2. Inherit your Admin class from RegexModelAdmin 3. enclose by / the field you want to regex with: `search_fields = ['/field/', ]`
Plaintext password hasher (encoded string: plain$1$mysecretpass). DANGEROUS!!! Use just if you know what you are doing!
Ever tried to unit test custom fields or abstract models? If so, you probably used a solution like [this one](http://djangosnippets.org/snippets/2843/). It surely works, but it has some issues: 1. Runs 'syncdb' several times. 2. It's not automatic. You must add the mixin or copy the code to each of the TestCases. This test runner adds to INSTALLED_APPS the 'app.tests' package for **each of the specified** apps, **before the 'syncdb' happens**. This has the [discovery runner](https://pypi.python.org/pypi/django-discover-runner) as a dependency (for 1.5 only, it will be the default in 1.6). However, it comes as a mixin so it should be easily pluggable to other test runners. If you intend to use the mixin with other runners, note that it imports 'app.tests.models' so it won't work with tests modules (tests.py). Your runner must "use" test packages (like discovery runner). # USAGE # in your settings.py: TESTAPPS_INSTALL = ( 'app1', 'app2', # ... ) TEST_RUNNER = 'testapp_runner.DiscoverTestAppRunner' # example import path # extra apps in command line. # run test for apps 'app1' to 'app4', adding 'app3' and 'app4' to the TESTAPPS_INSTALL setting. manage.py test app1 app2 app3 app4 --with-test-app=app3 --with-test-app=app4
Get derived model without storing their names or content types in databases. You write only one line, it expands into only one SQL-query (with many LEFT OUTER JOIN's). Model definition example: class BaseModel(models.Model): foo = models.IntegerField(null=True) derived = DerivedManager() class FirstChild(BaseModel): bar = models.IntegerField(null=True) class SecondChild(BaseModel): baz = models.IntegerField(null=True) How to use: >>> f = FirstChild.objects.create() >>> s = SecondChild.objects.create() >>> print list(BaseModel.objects.all() [<BaseModel object 1>, <BaseModel object 2>] >>> print list(BaseModel.derived.all() [<FirstChild object 1>, <SecondChild object 2>] >>> print BaseModel.derived.get(pk=s.pk) <SecondChild object 2>
Create a random integer with given length. - For a length of 3 it will be between 100 and 999. - For a length of 4 it will be between 1000 and 9999. Use it in a template like: {% random_number as my_id %} The id is {{ my_id }}
This is a generic admin action to select and export the data from admin view including the proxy models.
Simplified version of the snippet that renders model to PDF [http://djangosnippets.org/snippets/2540/](http://djangosnippets.org/snippets/2540/) This PDF view mixin for Django Class Based Views. See working project example: https://github.com/elena/django-pdfmixin-example --- This is based on the case scenario where you have a model which has a `DetailView`. You then construct a bespoke PDF for the same model that is unrelated in any way to the `DetailView`. The PDF needs to be returned as a `HTTPResponse` object. The model object is provided.
You can see full examples on the page [GitHub](https://github.com/abbasovalex/django-SplitJSONWidget-form)
Decorator to preserve view from logged users.
This is a javascript to call in the Media class of the ModelAdmin instance for the model, requires some additional css. The goal of such approach is that the add related functionality is supported, and works also with the django-mptt model fields. The new component can support resize functionality, in such case the jquery-ui resizable script is needed. For a complete documentation on this, and how to use it inside your project please visit this [blog post](http://www.abidibo.net/blog/2013/04/10/convert-select-multiple-widget-checkboxes-django-admin-form/)
nothing to see here...
South documentation [contains a description](http://south.readthedocs.org/en/0.7.6/fixtures.html#fixtures-from-migrations) of the way you can load fixtures inside the data-migrations. def forwards(self, orm): from django.core.management import call_command call_command("loaddata", "my_fixture.json") It seems pretty clear and easy, but in fact it does not work the way you expect from south migrations, because the fixture loading does not engage the **orm** object. So, it allows **loaddata** management command to use standard models loading mechanism, and it would provide the most recent version of the models, obviously, which may not correspond to the schema of the fixture`s data. To be ensured that migration will use appropriate version of the models for fixture loading you could use code like follows: class Migration(DataMigration): def forwards(self, orm): load_fixture('my_fixture.json', orm) class Migration(DataMigration): def forwards(self, orm): with southern_models(orm): call_command("loaddata", "my_fixture.json")
This file includes two Django view decorators `header` and `headers` that provide an easy way to set response headers. Also, because I have to work with a lot of cross domain requests, I include few shortcuts for convenience to set the Access-Control-Allow-Origin header appropriately.
This snippet *updates* http://www.djangosnippets.org/snippets/383/ and http://www.djangosnippets.org/snippets/1495/ for Django 1.4+, and adds support for sqlite3 and south. Original snippet text: A CompressedTextField to transparently save data gzipped in the database and uncompress at retrieval.
3110 snippets posted so far.