# Django Code Examples

Reference examples for each rule area. Read the relevant section when generating code for that area.

---

## Django Rules

```python
# ✅ Good: Logic in service
class UserService:
    @staticmethod
    def create_user(validated_data):
        return User.objects.create_user(**validated_data)

# View calls service
class UserCreateView(CreateAPIView):
    serializer_class = UserSerializer
    def perform_create(self, serializer):
        UserService.create_user(serializer.validated_data)
```

---

## Testing

```python
class UserApiTest(APITestCase):
    def test_create_user(self):
        url = reverse('user-list')
        data = {'email': 'test@example.com', 'password': 'password123'}
        response = self.client.post(url, data, format='json')
        assert response.status_code == status.HTTP_201_CREATED
```
