Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Internet > HTTP (WWW)

    django-logicaldelete 1.1 Beta 1 Dev3

    Download button

    No screenshots available
    Downloads: 251  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Patrick Altman | More programs
    MIT/X Consortium Lic... / FREE
    February 23rd, 2011, 07:06 GMT [view history]
    ROOT / Internet / HTTP (WWW)

     Read user reviews (0)  Refer to a friend  Subscribe

    django-logicaldelete description

    A base model that provides some extras for your models

    Developer comments

    django-logicaldelete is a small and simple app that I threw together to get some reuse out of something I do in nearly every project and every model I create. It's too easy for good data to get deleted and it be unrecoverable. It's also too easy to fix this by overriding the model's delete() method and just flagging records as deleted and then leveraging Django's Managers to override default behavior so that logically deleted items are not returned in querysets.

    There are two exceptions however, that I have found useful to this rule.

     1. In the admin I like to see everything with an indicator of whether or not it has been deleted, with the ability to filter down to just active records, (or deleted for that matter).
     2. I still think it is a valid request when an item is fetched for by it's primary key value, that the object should return, even if it is marked as deleted.

    Using django-logicaldelete

    Using the app is pretty simple:

     1. Put the logicaldelete sub-folder in your Python Path.
     2. Inherit from logicaldelete.models.Model for all models that you wish to share in this functionality.
     3. Create and/or Register admins for each of these models using logicaldelete.admin.ModelAdmin

    Additional

    Logical deletes are handled by date stamping a date_removed column. In addition, a date_created and date_modified columns will be populated as a convenience.

    Possible Extensions

    You can easily subclass these two classes to provide generic and useful functionality to your models.

    UUID Primary Key

    I typically using UUID fields for my primary keys because they enable me to shard my tables if and when I need to, in addition, they provide an obfuscated id to my data (people can't determine how many of a certain object I have in my database, if I don't want them to know, but simply looking an an integer id in the URL).

    Sequence Field

    Many times I find it useful to have an integer field on my models that allow for and explicitly controlled sequencing. I normally implement this as a sort descending implementation where the data is sorted from high to low by sequence value.

    In order to to implement this you'd subclass both the Model and ModelAdmin, where the Model would be an obvious simple addition of an IntegerField, the ModelAdmin, would override get_query_set, to do something like:

    class SequencedModel(logicaldelete.models.Model):
     sequence = models.IntegerField()


    class MyLogicalDeletedManager(logicaldelete.models.LogicalDeletedManager):
     def get_query_set(self):
     if self.model:
     qs = super(MyLogicalDeletedManager, self).get_query_set().filter(date_removed__isnull=True)
     if SequencedModel in inspect.getmro(self.model):
     qs = qs.order_by('-sequence')
     return qs



    Product's homepage

    Requirements:

    · Python
    · Django

    What's New in This Release: [ read full changelog ]

    · Changed everything to all_with_deleted on LogicalDeleteManager
    · LogicalDeleteManager moved from logicaldelete.models to logicaldelete.managers
    · Removed deleted and everything querysets from logicaldelete.models.Model

      


    TAGS:

    Logical Delete | Django logicaldelete | Django | logical | delete

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM