DELETE FROM table_name
WHERE "id" NOT IN
(SELECT MAX("dt"."id")
FROM table_name As dt
GROUP BY "dt"."field_that_records_have_duplicate_info_in", "dt"."another_field_that_records_have_duplicate_info_in");
Monday, December 15, 2008
Sunday, December 14, 2008
serve static files from the media folder using the django runserver command
It's never a good idea to serve files using the django manage.py runserver task but it comes in handy during developement when you don't want to setup a whole webserver like lighttpd or apache just for your sandbox.
SO I checked the documenation located at: http://docs.djangoproject.com/en/dev/howto/static-files/
and it walks you through how to setup the Django development script to serve files from the media folder using a secret "serve" view built into Django.
to turn it on you just drop in the route for it in the URLconf (ie urls.py) config file into the urlpatterns array:
urlpatterns = patterns('',
(r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
)
the above example uses a custom static variable from the settings.py file. If your going to do that make sure you import settings.py at the top your urls.py.
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.DEV_MEDIA_ROOT, 'show_indexes': True}),
)
That's pretty much it, except that you need to remember that if your going to use /media/ as the directory to serve your static files from to also change the name of the media folder that the Admin scaffolding defaults to. I started out with the scaffolding media path set to /media/ and it was not letting the route defined above execute. Took me forever to figure out that the two media folders were conflicting. SO in you settings.py make sure that ADMIN_MEDIA_PREFIX is set to something other than /media/ maybe something like:
ADMIN_MEDIA_PREFIX = '/admin_media/'
SO I checked the documenation located at: http://docs.djangoproject.com/en/dev/howto/static-files/
and it walks you through how to setup the Django development script to serve files from the media folder using a secret "serve" view built into Django.
to turn it on you just drop in the route for it in the URLconf (ie urls.py) config file into the urlpatterns array:
urlpatterns = patterns('',
(r'^site_media/(?P
{'document_root': settings.STATIC_DOC_ROOT}),
)
the above example uses a custom static variable from the settings.py file. If your going to do that make sure you import settings.py at the top your urls.py.
from django.conf import settingsAn even smarter way to do things is to only serve static files when you are in debug (dev) mode by including the followling logic to check for debug=true around your route definition:
...
(r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P
{'document_root': settings.DEV_MEDIA_ROOT, 'show_indexes': True}),
)
That's pretty much it, except that you need to remember that if your going to use /media/ as the directory to serve your static files from to also change the name of the media folder that the Admin scaffolding defaults to. I started out with the scaffolding media path set to /media/ and it was not letting the route defined above execute. Took me forever to figure out that the two media folders were conflicting. SO in you settings.py make sure that ADMIN_MEDIA_PREFIX is set to something other than /media/ maybe something like:
ADMIN_MEDIA_PREFIX = '/admin_media/'
Django 1.x and tinyMCE
There is a lot of miss-documentation out on the web right now about how to setup wysiwyg editors to work with the django Admin scaffolding.
The current production release of django (1.0.2) at the time of this article is using the django newforms library for the admin scaffolding. I think at somepoint leading right up to the 1.0 major release there was two ways of customizing this newforms admin scaffolding. One involved including a special Admin class inside of all of your model classes
ex:
(from models.py)
class StaffBio(models.Model):
name = models.CharField("Name", maxlength=128,db_index=True)
position = models.CharField("Position", maxlength=128,db_index=True)
bio = models.TextField("Biography")
fote = ImageField("Photo", null=True,
blank=True, upload_to="E:/home/dev/storage/StaffBio/fote")
pageorder = models.IntegerField("Appearance on bio page",
choices=SITEORDER_CHOICES, db_index=True)
jobcat = models.CharField(maxlength=1,
choices=JOBCAT_CHOICES, db_index=True, default='P')
def __repr__(self):
return self.name
class Meta:
ordering = ['name', 'jobcat', 'status']
verbose_name = "Staff Bio"
class Admin:
fields = (
('Content', {'fields': ('name','position','bio','fote', 'jobcat', 'pageorder')}),
)
list_display = ( 'name', 'jobcat' )
list_filter = ['status', 'jobcat']
search_fields = ['name']
js = ['tiny_mce/tiny_mce.js', 'js/textareas.js']
and the other (currently best practice way) of doing it involved creating a new special configuration file called admin.py and putting it in the same directory as your models.py
ex:
(from admin.py)
from mew.cms.models import ArtistsInResidencePage
from django.contrib import admin
class ArtistsInResidencePageAdmin(admin.ModelAdmin):
class Media:
js = ('tiny_mce/tiny_mce.js', 'textarea.js')
admin.site.register(ArtistsInResidencePage, ArtistsInResidencePageAdmin)
so to get tiny mce to work, upload it to your media folder and then create new classes inside your admin.py file called ModelNameAdmin then register both the original model and it's Admin counterpart witha call do admin.site.register(ModelName, ModelNameAdmin)
remember that the location of the .js files is relative to the /media/ folder meaning that whatever you put in for the two values here: js = ('tiny_mce/tiny_mce.js', 'textarea.js') will have the word /media/ prepended to it.
The current production release of django (1.0.2) at the time of this article is using the django newforms library for the admin scaffolding. I think at somepoint leading right up to the 1.0 major release there was two ways of customizing this newforms admin scaffolding. One involved including a special Admin class inside of all of your model classes
ex:
(from models.py)
class StaffBio(models.Model):
name = models.CharField("Name", maxlength=128,db_index=True)
position = models.CharField("Position", maxlength=128,db_index=True)
bio = models.TextField("Biography")
fote = ImageField("Photo", null=True,
blank=True, upload_to="E:/home/dev/storage/StaffBio/fote")
pageorder = models.IntegerField("Appearance on bio page",
choices=SITEORDER_CHOICES, db_index=True)
jobcat = models.CharField(maxlength=1,
choices=JOBCAT_CHOICES, db_index=True, default='P')
def __repr__(self):
return self.name
class Meta:
ordering = ['name', 'jobcat', 'status']
verbose_name = "Staff Bio"
class Admin:
fields = (
('Content', {'fields': ('name','position','bio','fote', 'jobcat', 'pageorder')}),
)
list_display = ( 'name', 'jobcat' )
list_filter = ['status', 'jobcat']
search_fields = ['name']
js = ['tiny_mce/tiny_mce.js', 'js/textareas.js']
and the other (currently best practice way) of doing it involved creating a new special configuration file called admin.py and putting it in the same directory as your models.py
ex:
(from admin.py)
from mew.cms.models import ArtistsInResidencePage
from django.contrib import admin
class ArtistsInResidencePageAdmin(admin.ModelAdmin):
class Media:
js = ('tiny_mce/tiny_mce.js', 'textarea.js')
admin.site.register(ArtistsInResidencePage, ArtistsInResidencePageAdmin)
so to get tiny mce to work, upload it to your media folder and then create new classes inside your admin.py file called ModelNameAdmin then register both the original model and it's Admin counterpart witha call do admin.site.register(ModelName, ModelNameAdmin)
remember that the location of the .js files is relative to the /media/ folder meaning that whatever you put in for the two values here: js = ('tiny_mce/tiny_mce.js', 'textarea.js') will have the word /media/ prepended to it.
Tuesday, December 9, 2008
Tuesday, December 2, 2008
delete all files that match a filename in the current directory recursively
find ./ -name _left_col -print0 | xargs -0 rm -rf
Subscribe to:
Posts (Atom)