Django - dumpdata truncates the last n lines

Does anyone have a simple solution to use (or modify) the dumpdates to scroll through a simple table to the last n lines. I like to use dump data for test devices, but the data size has become so large that it makes no sense. BTW - I did not design the table, I am just a suction cup that needs to deal with it.

For those who may ask what the structure looks like here.

From the side of Django

class GridResourceUsage(models.Model):
    """Sampled point in time of license usage for individual grid resource. Includes who and quanity."""
    timestamp = models.DateTimeField(db_index=True)
    grid_license_resource = models.ForeignKey(GridLicResource)
    total    = models.IntegerField(default=None, null=True)
    limit    = models.IntegerField(default=None, null=True)
    free     = models.IntegerField(default=None, null=True)
    intern   = models.IntegerField(default=None, null=True)
    extern   = models.IntegerField(default=None, null=True)
    waiting  = models.IntegerField(default=None, null=True)
    def __unicode__(self):
        return str("GRU-" + self.grid_license_resource.name) 
    class Meta:
        ordering = ['-timestamp']
    @models.permalink
    def get_absolute_url(self):
        return('hist_res_id', (), {'resource': str(self.grid_license_resource.name), 'id':str(self.id)})

MySQL side

CREATE TABLE `gridresource_gridresourceusage` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `timestamp` datetime NOT NULL,
  `grid_license_resource_id` int(11) NOT NULL,
  `total` int(11) DEFAULT NULL,
  `limit` int(11) DEFAULT NULL,
  `free` int(11) DEFAULT NULL,
  `intern` int(11) DEFAULT NULL,
  `extern` int(11) DEFAULT NULL,
  `waiting` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `gridresource_gridresourceusage_timestamp` (`timestamp`),
  KEY `gridresource_gridresourceusage_grid_license_resource_id` (`grid_license_resource_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2891167 DEFAULT CHARSET=latin1;
+3
source share
1 answer

I'm not sure what dumpdatacan do what you ask for.

? , .

# Create queryset you want
n = SomeModel.objects.count()-1 # Row offset counting from the end
queryset = SomeModel.objects.all()[n:]

# Serialize that queryset to json in this case
from django.core import serializers
data = serializers.serialize("json", queryset)

# And write it into the file
f = open('data.json', 'w')
f.write(data)
f.close()

, dumpdata. ( dumpdata )

+4

Source: https://habr.com/ru/post/1762299/


All Articles