Skip to main content

Build Status django-swapfield ================

Easy! When you use django-swapfield if the value is saved in other record, values are swapped! You can configure what
conditions must be repeated in both records to make the change.

How to

~~~~ {.sourceCode .bash}
$ pip install django-swapfield
$ # Define a SwapIntegerField in your model with unique_for_fields param (fields coincidence to can swap values)
$ # That SwapIntegerField can’t be a part of unique_together or unique restriction.
~~~~

Uses e.g.

  • Uniform number in sport team.

  • Race number in an athletic competition.

  • Any scenario when you want to swap values without reordering.

example

~~~~ {.sourceCode .bash}
from swapfield.fields import SwapIntegerField
class Player(models.Model):
name = models.CharField(max_length=30)
team = models.ForeignKey(Team)
number = SwapIntegerField(unique_for_fields=[‘team’])
# can swap “number” if “team” has the same value
~~~~

Available fields

  • SwapIntegerField

Method

  • Current status allow swap values if not exists unique/unique_together restriction. First, get the registry (if exists) what contains the new value to assign it the old value from registry what currently is saving. When current registry is saved, replace the other registry with old value.

  • In next versions, other method will be used when exists unique/unique_together restriction.

to-do list

  • [ ] Two or more django-swapfield in the same object.

  • [ ] Alternative method when exists unique/unique_together restriction

  • [ ] Friendly validation error with Django Admin (no Fatal error)

  • [ ] Abstract django-swap-field

  • [ ] SwapCharField

  • [x] Tests for functionality

  • [ ] Tests for migrations

  • [ ] Config setting to choose swap value when a new record (not edited) get a value that exists in database: choose the max value +1 or the first available.

Metadata

Release files for django-swapfield 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-swapfield 0.1.1
File Size Uploaded
django-swapfield-0.1.1.tar.gz 7.2 kB Details

Release files / django-swapfield-0.1.1.tar.gz

Download URL django-swapfield-0.1.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9e6cd6d4c32d5a0927fa23bf670ebbbc525aa36928b81199c3ac025d23ddfefa
BLAKE2b-256 checksum
How to use checksums
bef0dcb9ea1d28b43ff2ee1cae6a25c67cad0dc9564f95e508d18fec2f085fc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page