Git Product home page Git Product logo

django-paranoid-model's Introduction

Hi there ๐Ÿ‘‹

Header

As a Software Development Engineer, I specialize in creating robust and efficient backend solutions. With a focus on software architecture design, I have expertise in crafting scalable solutions across various technologies and frameworks.

As a senior professional, I am dedicated to staying updated on industry trends and utilizing my passion for software architecture to contribute effectively to projects.

from github import Developer


class AboutMe(Developer):
    name = "Luan"
    last_name = "Rodrigues"
    position = "Software Development Engineer 3"
    nationality = "Brazilian"
    langauges = ["Portuguese", "English"]
  • ๐ŸŽ“ Computer Science Bachelor Degree.
  • ๐ŸŒฑ Iโ€™m currently working with Golang and ecossystem
  • ๐Ÿ’Œ How to reach me:
  • โšก Fun fact: I'm a windows user.
  • โ˜ Checkout my personal website

Hands-on Skills

๐Ÿ’ช Programing Languages

My Skills

๐Ÿ”จ Frameworks

My Skills

๐Ÿ’พ Databases

My Skills

Tools

My Skills

โšก Recent Activity

  1. ๐ŸŽ‰ Merged PR #2 in DarknessRdg/DarknessRdg
  2. ๐Ÿ’ช Opened PR #2 in DarknessRdg/DarknessRdg
  3. ๐ŸŽ‰ Merged PR #1 in DarknessRdg/DarknessRdg
  4. ๐Ÿ’ช Opened PR #1 in DarknessRdg/DarknessRdg

django-paranoid-model's People

Contributors

codacy-badger avatar darknessrdg avatar dependabot[bot] avatar jeromelefeuvre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-paranoid-model's Issues

Paranoid restore not working with multiple database when using is none

I have many databases , but no default. When I have a soft deleted instance and i call method restore() it tries to use default database, instead of database where instace comes from.

instance = MyModel.objects.using('database2').get_deleted()

intance.restore()  # this line brokes beacuse I have no default database. 
# But it should use 'database2', wich is database where instance is saved

But if I pass dabase's name it works just fine:

intance.restore('databse2')

Tracekback

>>> instance.restore()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "...\venv\lib\site-packages\paranoid_model\models.py", line 71, in restore
    for related in self._related_objects(using):
  File "...\venv\lib\site-packages\paranoid_model\models.py", line 88, in _related_objects
    collector.collect([self])
  File "...\venv\lib\site-packages\django\contrib\admin\utils.py", line 181, in collect
    return super().collect(objs, source_attr=source_attr, **kwargs)
  File "...\venv\lib\site-packages\django\db\models\deletion.py", line 244, in collect
    if sub_objs:
  File "...\venv\lib\site-packages\django\db\models\query.py", line 280, in __bool__
    self._fetch_all()
  File "...\venv\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "...\venv\lib\site-packages\django\db\models\query.py", line 57, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1138, in execute_sql
    sql, params = self.as_sql()
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 490, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 257, in get_select
    sql, params = self.compile(col)
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
    sql, params = node.as_sql(self, self.connection)
  File "...\venv\lib\site-packages\django\db\models\expressions.py", line 770, in as_sql
    return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
  File "...\venv\lib\site-packages\django\db\models\sql\compiler.py", line 413, in quote_name_unless_alias
    r = self.connection.ops.quote_name(name)
  File "...\venv\lib\site-packages\django\db\backends\dummy\base.py", line 20, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Paranoid not removing deleted when querying on previous queryset

I ran into this problem when quering on a previous queryset.

I was creating a new queryset like this, because i need to use multiple databases.

previou_query = MyParanoid.objects.using('database2')
# once done that, a queryset is created

After get my queryset targeted to a database, i neet to query, but when i do the following, django paranoid also filters deleted instances

query1 = previous_query.filter()
# includes deleted instances

To fixe i needed to explicit pass parameter with_deleted like this:

query1 = previous_query.filter(with_deleted=False)
# excludes deleted instances

query1 = previous_query.filter(with_deleted=True)
# includes deleted instances

AttributeError when dealing with models not Paranoid

I have a model with a ForeignKey relation with a Paranoid model, and i'ts throwing an AttributeError because the model doesn't have a is_soft_deleted attribute.

Traceback (most recent call last):
  ...
    return queryset.filter(with_deleted=False)
  File "...\paranoid_model\queryset.py", line 125, in filter
    if kwargs[key].is_soft_deleted:
AttributeError: 'ModelNotParanoid' object has no attribute 'is_soft_deleted'

Queryset `get_or_create` raises SoftDeleteException

A simple issue, demonstrated better by example:
image

Simply replacing it with get_or_restore does not solve how I intend to use this method for example:
image

update_or_create also uses get_or_create, maybe it would be better to override get_or_create and catch the SoftDeleteException ?

deleted_at query is lost when Q() is added in filter

Got a problem when trying to use Q()...

Simple to understand by example ^^ :

In [2]: print(WidgetItem.objects.filter(id=3).query)
SELECT * FROM `nfb_widgets_widgetitem` WHERE (`nfb_widgets_widgetitem`.`id` = 3 AND `nfb_widgets_widgetitem`.`deleted_at` IS NULL) ORDER BY `nfb_widgets_widgetitem`.`order` ASC

In [3]: print(WidgetItem.objects.filter(Q(widget__id=3)).query)
SELECT * FROM `nfb_widgets_widgetitem` ORDER BY `nfb_widgets_widgetitem`.`order` ASC

Thanks!

Delete is deleting models that aren't paranoid

Delete is deleting models that aren't paranoid

When a paranoid model is delete with hard_delete=False , all related models are also delete, including regular models

for example:

Look at the model bellow. Person is Paranoid, but Clothes is not paranoid.

class Person(paranoid_model.Paranoid):
    name = models.CharField(max_length=255)

class Clothes(models.Model):
    description = models.CharField(max_length=255)
    person = models.ForeignKey(Person, on_delete=models.CASCADE, related_name='my_clothes')

When the following command is performed it will delete related clothe from database

person = Person.objects.create(name='Person name')

Clothes.objects.create(description='T-Shirt', person=person)

person.delete()

When delete person instance, the clothe just created will be deleted from database.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.